Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2010 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/628478 to your computer and use it in GitHub Desktop.
Save anonymous/628478 to your computer and use it in GitHub Desktop.
Dumping fields, including backing fields for automatic properties, through reflection
void Main()
{
Test t = new Test { Text = "Test" };
t.AccessFields();
}
public class Test
{
public void AccessFields()
{
foreach (var f in GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
{
var value = f.GetValue(this);
Debug.WriteLine(f.Name + " = " + value);
}
}
public string Text { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment