Relflection use and objects

  • Thread starter Thread starter Roger Webb
  • Start date Start date
R

Roger Webb

Hey Yall,

I'm trying to get a list of properties in an object and am having trouble with the Values. My main Problem is with the difference in the types... For integers I want just the Value.ToString() but for Strings and other types I want it with quotes around it. Any Ideas??

Type DRType = request.GetType();
PropertyInfo[] PropInfo = DRType.GetProperties();
foreach(PropertyInfo prop in PropInfo)
{
Listing.Append(prop.Name+" "+?????);
}

- Roger
 
Hi Roger,

Will this work?

foreach(PropertyInfo prop in PropInfo)
{
string rawValue = prop.GetValue(request, null).ToString();
string value = prop.PropertyType == typeof(int) ?
rawValue : "\"" + rawValue + "\"";

Listing.Append(prop.Name + ": " + value + "\n");
}

Joe
--
http://www.csharp-station.com
Hey Yall,

I'm trying to get a list of properties in an object and am having trouble with the Values. My main Problem is with the difference in the types... For integers I want just the Value.ToString() but for Strings and other types I want it with quotes around it. Any Ideas??

Type DRType = request.GetType();
PropertyInfo[] PropInfo = DRType.GetProperties();
foreach(PropertyInfo prop in PropInfo)
{
Listing.Append(prop.Name+" "+?????);
}

- Roger
 
Back
Top