Last active
October 14, 2015 08:39
-
-
Save whyleee/fc65391e61fe49e8eb94 to your computer and use it in GitHub Desktop.
Function to write RDB C# objects to console
This file contains 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
private static void WriteObject(object obj, int indent = 0, string suffix = null) | |
{ | |
foreach (var prop in obj.GetType().GetProperties()) | |
{ | |
var value = prop.GetValue(obj); | |
if (prop.PropertyType.FullName.StartsWith("RDB") && !prop.PropertyType.IsEnum && value != null) | |
{ | |
Console.Write(new string(' ', indent)); | |
Console.WriteLine(prop.Name + ":"); | |
WriteObject(value, indent + 2); | |
} | |
else if (typeof (IEnumerable).IsAssignableFrom(prop.PropertyType) && prop.PropertyType != typeof(string)) | |
{ | |
Console.Write(new string(' ', indent)); | |
Console.WriteLine(prop.Name + ": ["); | |
foreach (var item in (IEnumerable) value) | |
{ | |
if (item.GetType().FullName.StartsWith("RDB") && !item.GetType().IsEnum) | |
{ | |
WriteObject(item, indent + 2); | |
} | |
else | |
{ | |
Console.Write(new string(' ', indent + 2)); | |
Console.WriteLine(item); | |
} | |
} | |
Console.Write(new string(' ', indent)); | |
Console.WriteLine("]"); | |
} | |
else | |
{ | |
Console.Write(new string(' ', indent)); | |
Console.WriteLine(prop.Name + ": " + value + suffix); | |
} | |
} | |
if (indent == 0) | |
{ | |
Console.WriteLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment