[Mono-list] Re: Retrieving the Properties of a class at runtime
Robert Jordan
robertj@gmx.net
Thu, 30 Dec 2004 16:04:52 +0100
Shawn,
> Can someone direct me to documentation on how to iterate over only the
> properties in a class at runtime. I have a class that is nothing but
> properties and instead of typing out
> Console.WriteLine(someObject.someProperty) it would rather iterate over
> the available properties.
untested:
using System.Runtime.Reflection;
...
static void DumpProperties(object o) {
foreach (PropertyInfo pi in o.GetType().GetProperties()) {
Console.WriteLine("Name: {0}; value: {1}",
pi.Name, pi.GetValue(o, null));
}
}
bye
Rob