Created
July 22, 2009 21:43
-
-
Save DoubleBrotherProgrammer/152302 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not of class! of object !
How could do it to enumerate Class properties ? without creating instance of class?