Skip to content

Instantly share code, notes, and snippets.

@musicm122
Created January 23, 2013 23:21
Show Gist options
  • Save musicm122/4615640 to your computer and use it in GitHub Desktop.
Save musicm122/4615640 to your computer and use it in GitHub Desktop.
Diagnostic Object Extensions
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