Created
June 30, 2017 21:20
-
-
Save svick/8041b69b568e7ab6ff917ec814bcc30d 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
| 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