Created
January 23, 2013 23:21
-
-
Save musicm122/4615640 to your computer and use it in GitHub Desktop.
Diagnostic Object Extensions
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
public static class DiagnositcObjectExtensions | |
{ | |
public static string ToDiagnosticInfoString(this IEnumerable items) | |
{ | |
var retval = String.Empty; | |
if(items.Count()>0) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
sb.AppendLine(“—–BEGIN DIAGNOSTIC——-”); | |
foreach(var item in items) | |
{ | |
sb.AppendLine(item.ToDebugString()); | |
} | |
sb.AppendLine(“—–END DIAGNOSTIC———”); | |
retval = sb.ToString(); | |
} | |
return retval; | |
} | |
public static string ToDebugString(this T obj) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
Type _type = obj.GetType(); | |
PropertyInfo[] pi = _type.GetProperties(); | |
sb.AppendFormat(“Type={0}\r\n”,typeof(T).ToString()); | |
sb.AppendLine(“Properties”); | |
foreach (var item in pi) | |
{ | |
sb.AppendFormat(“{0} {1} = {2}\r\n”,item.PropertyType.ToString(), | |
item.Name, | |
item.GetValue(obj)); | |
} | |
return sb.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment