Skip to content

Instantly share code, notes, and snippets.

@supasympa
Created April 21, 2011 16:32
Show Gist options
  • Save supasympa/934932 to your computer and use it in GitHub Desktop.
Save supasympa/934932 to your computer and use it in GitHub Desktop.
Inspect the properties of an object and return the properties and the value followed by a line break (one level deep).
public static string Properties(object o, Type type, string linebreak)
{
StringBuilder sb = new StringBuilder();
foreach (var prop in type.GetProperties())
{
if (prop.CanRead)
{
var value = prop.GetValue(o, null);
if (value != null)
{
sb.Append(String.Format("{0} = {1}{2}", prop.Name.ToString(), value, linebreak));
}
}
}
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment