Created
April 21, 2011 16:32
-
-
Save supasympa/934932 to your computer and use it in GitHub Desktop.
Inspect the properties of an object and return the properties and the value followed by a line break (one level deep).
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
| public static string Properties(object o, Type type, string linebreak) | |
| { | |
| StringBuilder sb = new StringBuilder(); | |
| foreach (var prop in type.GetProperties()) | |
| { | |
| if (prop.CanRead) | |
| { | |
| var value = prop.GetValue(o, null); | |
| if (value != null) | |
| { | |
| sb.Append(String.Format("{0} = {1}{2}", prop.Name.ToString(), value, linebreak)); | |
| } | |
| } | |
| } | |
| return sb.ToString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment