Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DoubleBrotherProgrammer/152302 to your computer and use it in GitHub Desktop.
Save DoubleBrotherProgrammer/152302 to your computer and use it in GitHub Desktop.
#region dumpClassProperties
/// <summary>
/// Pass in a class object and this will return a string
/// in "name = value \n" format of all properties and corresponding
/// property values
///
/// Usage :
///
/// MyClass mc = new MyClass();
///
/// mc.property1 = "number one";
/// mc.property2 = "second property";
/// mc.three = 333;
///
/// string dump = dumpClassProperties( mc );
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static string dumpClassProperties(Object obj)
{
System.Text.StringBuilder sb = new StringBuilder();
foreach ( System.Reflection.FieldInfo fi in obj.GetType().GetFields())
{
sb.Append(fi.Name + " = " + fi.GetValue(obj) + "\n");
}
return sb.ToString();
}
#endregion
@Diaskhan
Copy link

Diaskhan commented Nov 24, 2018

Not of class! of object !

How could do it to enumerate Class properties ? without creating instance of class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment