System.Reflection

  • Thread starter Thread starter Arne Garvander
  • Start date Start date
How can get all the objects/data member in a class thru reflection.

Assuming i understand your question correctly, if you have already
done:

MyClass myClass = new MyClass();

Then to get a list of properties in MyClass:

PropertyInfo[] propertyInfo = myClass.GetType().GetProperties();

To get a list of methods:

MethodInfo[] methodInfo = myClass.GetType().GetMethods();
 
My class has 20 public variables. None of them showed up in GetProperties, as
far as I can see.
--
Arne Garvander
(I do classic Asp to get paid and WPF for fun.)


How can get all the objects/data member in a class thru reflection.

Assuming i understand your question correctly, if you have already
done:

MyClass myClass = new MyClass();

Then to get a list of properties in MyClass:

PropertyInfo[] propertyInfo = myClass.GetType().GetProperties();

To get a list of methods:

MethodInfo[] methodInfo = myClass.GetType().GetMethods();
 
My class has 20 public variables. None of them showed up in GetProperties, as
far as I can see.

Because they are not properties, they are field , which BTW is a bad
design expose them outside the class.
You can use either GetFields() or Filter GetMembers()
 
Back
Top