Anonymous (owner)

Revisions

  • 2c3994 Fri Jul 17 21:02:59 -0700 2009
gist: 149401 Download_button fork
public
Public Clone URL: git://gist.github.com/149401.git
Embed All Files: show embed
Dump properties and values of a custom class #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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