Dump an arbitrary object To Html String

Posted by Michael Freidgeim on Geeks with Blogs See other posts from Geeks with Blogs or by Michael Freidgeim
Published on Sat, 14 Apr 2012 03:50:05 GMT Indexed on 2012/04/14 5:30 UTC
Read the original article Hit count: 204

Filed under:

For debugging purposes me and my collegue wanted to dump details of the arbitrary object, and created function that uses LINQPad Dump functionality (thanks to http://stackoverflow.com/a/6035014/52277 and original http://linqpad.uservoice.com/forums/18302-linqpad-feature-suggestions/suggestions/447166-make-dump-extension-method-available-in-visual-s discussion)
   public static string DumpToHtmlString<T>(this T objectToSerialize)
       {
           string strHTML =
"";

           try
           {
               var writer = LINQPad.
Util.CreateXhtmlWriter(true);
               writer.Write(objectToSerialize);
               strHTML = writer.ToString();
           }
           catch (
Exception exc)
           {
               
Debug.Assert(false, "Investigate why ?" + exc);
           }

           return strHTML;
       }

You will need to add the linqpad executable as a reference in your project.


TO DO similar in plain text ,look at https://github.com/ServiceStack/ServiceStack.Text StringExtensions , e.g. JsonSerializer/CsvSerializer

or http://objectdumper.codeplex.com/

© Geeks with Blogs or respective owner