Skip to content

Instantly share code, notes, and snippets.

@svick
Created June 30, 2017 21:20
Show Gist options
  • Select an option

  • Save svick/8041b69b568e7ab6ff917ec814bcc30d to your computer and use it in GitHub Desktop.

Select an option

Save svick/8041b69b568e7ab6ff917ec814bcc30d to your computer and use it in GitHub Desktop.
void Main()
{
DumpAnonymousType(new { i = 42, j = 13 });
DumpAnonymousType((i: 42, j: 13));
}
void DumpAnonymousType(object o)
{
var properties = o.GetType().GetProperties();
if (!properties.Any())
throw new InvalidOperationException();
string.Join("; ", properties.Select(p => $"{p.Name}: {p.GetValue(o)}")).Dump();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment