Head.SmackOnTable();

Contains Nuts.

Output all properties for any object

without comments


private void outputValues(object inputObject)
{
List<PropertyInfo> propertyInfos = new List<PropertyInfo>(inputObject.GetType().GetProperties());

foreach (PropertyInfo info in propertyInfos)
{
try
{
object obj = info.GetValue(inputObject, null);
if (obj == null)
{
continue;
}
Console.WriteLine("[{0}]:{1}", info.Name, obj.ToString());

}
catch (Exception)
{
continue;
}

}

}

Replace the Console.WriteLine with whatever you want, log4net,Ā  Debug, trace, etc, and it works!

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DotNetKicks
  • DZone

Written by Monty

July 22nd, 2009 at 9:51 am

Posted in Code Snippet

Tagged with ,

Leave a Reply