C# Get class properties

  • Thread starter Thread starter jared lynch
  • Start date Start date
J

jared lynch

I'm trying to write a class that will get all the properties of a
class and store it in xml file. So far I'm able to do this on a basic
class, meaning a class that has no array's or instances of other
classes within it, just some basic properties (ie. strings, ints, etc)
Does anyone have an idea of how i'd iterate through a classes property
if it's an arraylist to grab the properties within the arraylist as
well?
 
Using reflection you can obtain the MemberInfo property,
then objtain property types, check if it implements ICollection and then
iterate...

Type MyType =Type.GetType("System.IO.BufferedStream");
PropertyInfo[] propInfoArray = MyType.GetProperties();
ICollection collection = null;
object obj = null;
foreach (PropertyInfo propInfo in propInfoArray )
{
if ( (obj = propInfo.GetValue(null, null)) is ICollection )
collection = (ICollection)obj;
}


Iterate through collection object
 
Back
Top