Hey All,
I've got a class that I'm trying to get a listing of the properties...ki nda
like one of the Reflection examples from Microsoft. However, unlike their
example, I need to get the value as well. And am having trouble
understanding how the GetValue() function of the PropertyInfo should be
setup as below.
Also, with it coming back as an object, is there a way to get it recast so
that the DoSomething function will work?
I'm hopeing/thinking/praying.. that there is a way to make the code below
have StringBuilder1. ToString() be
"-FirstField='Str ing1'-SecondField=2"
Any help ... or comments would be appreciated.
- Roger
class LocalClass
{
public string FirstField;
public int SecondField;
}
<snip most of procedure>
....
LocalClass LocalClass1 = new LocalClass();
LocalClass1.Fir stField = "String1";
LocalClass1.Sec ondField = 2;
Type DRType = LocalClass1.Get Type();
PropertyInfo[] PropInfo = DRType.GetPrope rties();
foreach(Propert yInfo prop in PropInfo)
{
if(!(prop.Prope rtyType.IsArray ))
{
StringBuilder1. Append("-"+DoSomething(p rop.Name,
prop.GetValue(p rop, ????)));
}
}
....
public string DoSomething(str ing A, string B)
{
return string.Format(" {0}='{1}'",A,B) ;
}
public string DoSomething(str ing A, int B)
{
return string.Format(" {0}={1}",A,B.To String());
}
I've got a class that I'm trying to get a listing of the properties...ki nda
like one of the Reflection examples from Microsoft. However, unlike their
example, I need to get the value as well. And am having trouble
understanding how the GetValue() function of the PropertyInfo should be
setup as below.
Also, with it coming back as an object, is there a way to get it recast so
that the DoSomething function will work?
I'm hopeing/thinking/praying.. that there is a way to make the code below
have StringBuilder1. ToString() be
"-FirstField='Str ing1'-SecondField=2"
Any help ... or comments would be appreciated.
- Roger
class LocalClass
{
public string FirstField;
public int SecondField;
}
<snip most of procedure>
....
LocalClass LocalClass1 = new LocalClass();
LocalClass1.Fir stField = "String1";
LocalClass1.Sec ondField = 2;
Type DRType = LocalClass1.Get Type();
PropertyInfo[] PropInfo = DRType.GetPrope rties();
foreach(Propert yInfo prop in PropInfo)
{
if(!(prop.Prope rtyType.IsArray ))
{
StringBuilder1. Append("-"+DoSomething(p rop.Name,
prop.GetValue(p rop, ????)));
}
}
....
public string DoSomething(str ing A, string B)
{
return string.Format(" {0}='{1}'",A,B) ;
}
public string DoSomething(str ing A, int B)
{
return string.Format(" {0}={1}",A,B.To String());
}
Comment