How to use the LinqPad.Dump () extension method in Visual Studio?

LINQPad is striking, the Dump() extension method, which maps objects and structures of almost any type, anonymous or not, to the console, is especially useful.

Initially, when I switched to Visual Studio 2010, I tried to create my own Dump method, using a delegate, to get the rendering values ​​for anonymous types, etc. It gets quite complicated, albeit while it was fun, and first I need a reliable implementation. By choosing the LINQPad code in the reflector, I’m even more confident that I will not return its implementation.

Is there a free library that I can enable to provide Dump functionality?

+45
c # linqpad
Apr 23 '10 at 14:47
source share
4 answers

Take a look here (your path may vary):

C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Samples \ 1033 \ CSharpSamples.zip \ LinqSamples \ ObjectDumper

+34
Apr 23 2018-10-23T00:
source share

I wrote an extension method for Object that uses the Json.Net serializer with a nice format option. JSON is fairly easy to read when formatting. You are missing information about the type, but I do not know what you need, especially considering how simple it is. He has not failed me yet. I use Json.Net, not MS ', because it has the ability to handle circular links in complex graphs where MS' could not or was not at the time I thought about it.

  using Newtonsoft.Json; public static class Dumper{ public static string ToPrettyString(this object value) { return JsonConvert.SerializeObject(value, Formatting.Indented); } } 
+47
Apr 23 2018-10-23T00:
source share

diceguyd30 answer is obtained from the discussion (especially the comments by Pat Kuyava and anunay ) and describes how to invoke the linqPad Dump implementation from both C # and VB.

  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; } 
+8
Feb 24 '12 at 20:59
source share

There is also a class library called ObjectDumper is available as a NuGet package.

+7
Feb 03 2018-12-12T00:
source share



All Articles