Is there a library that provides a formatted Dump () function like LinqPad?

I work with a lot of Linq queries in my code, and I'm looking for a library that provides a formatted Dump () function similar to the LinqPad function. The LinqPad Dump () extension method is really very good because it handles nested collections very well.

Ideally, it will print beautiful tables in plain text, but I would love to splash out HTML or other well-formatted data.

The VS ObjectDumper sample does not cut it at all.

+14
linq linqpad
May 17 '11 at 15:06
source share
2 answers

This is what I used:

Special thanks to this topic (especially the comments by Pat Kuyava and anunay)

C # (straight from Pat Kujawa's comment (although I did this so that it comes back myself, so that it works as a linqpad version)):

public static T Dump<T>(this T o) { var localUrl = Path.GetTempFileName() + ".html"; using (var writer = LINQPad.Util.CreateXhtmlWriter(true)) { writer.Write(o); File.WriteAllText(localUrl, writer.ToString()); } Process.Start(localUrl); return o; } 

VB (my conversion, since I need it in a VB application):

 Public Module LinqDebugging <System.Runtime.CompilerServices.Extension()> Public Function Dump(Of T)(ByVal o As T) As T Dim localUrl = Path.GetTempFileName() + ".html" Using writer = LINQPad.Util.CreateXhtmlWriter(True) writer.Write(o) File.WriteAllText(localUrl, writer.ToString()) End Using Process.Start(localUrl) Return o End Function End Module 

You will need to add the linqpad executable as a reference in your project , as well as System.IO and System.Diagnostics

This launches your default web browser, showing the exact output linqpad will generate.

+20
May 17 '11 at 17:55
source share

As diceguyd30 points out, you can actually access the LINQPad executable directly in your code and create it yourself. This will work best if you try to output HTML to the interface as part of the normal execution of your program.

If your goal is to create debugging data that you can monitor while your program is running, another option is to use the Console.Write(object) method, and then set Console.Out to something that can intelligently format objects. For example, you can reference your executable from LINQPad and use it to execute the method you are debugging, and LINQPad will handle any calls to Console.WriteLine(object) in the same way as calling object.Dump() .

+3
May 17 '11 at 19:24
source share



All Articles