.NET Tip : How to print all property names & values of .NET class ?
Heres .net code
public static void PrintClassMemberValues(object source, System.IO.TextWriter tw)
{
Type sourceType = source.GetType();
tw.WriteLine(“——————- ” + sourceType.Name + ” ——————- “);
foreach (PropertyInfo sourceProperty in sourceType.GetProperties())
{
tw.WriteLine(sourceProperty.Name + “=” + sourceProperty.GetValue(source, null));
}
tw.WriteLine(“——————-“);
}
Usage :
MyClass helloClass = new MyClass();
helloClass.Name=”Test”;
helloClass.ID=1234;
PrintClassMemberValues(helloClass,Console.Out);