Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

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/

Posted on Saturday, April 14, 2012 2:50 PM ASP.NET , .Net Framework , Testing/Debugging/Logging | Back to top


Comments on this post: Dump an arbitrary object To Html String

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net