Make Dump() extension method available in Visual Studio
Dump() extension method is #1 reason I love and use LinqPad.
It would be great if I could add LinqPad.exe as reference to my Visual Studio project and call Dump() extension method on any of my objects.
As Visual Studio does not have any window to display HTML we could have two variants to Dump() extension method
DumpHTML() which return output as HTMLtext and
DumpText() which returns the output as space formatted text in a ASCII Table
User may choose to print the output to the Console, Output Window or write to the disk.
I you think generating ASCII table is lot of work, I'm fine with HTML output as well.
Please please I need this feature added right now...
-
Will保哥(保哥) commented
I'm using ObjectDumper.NET from Visual Studio. It works perfectly.
-
Jared commented
Peter - great recommendation. ServiceStack.Text is awesome!
-
Peter commented
Why not nuget ServiceStack.Text and use that Dump method in VS
-
Amit Hegde commented
I wrote a simple visualizer which uses LinqPad Dump method to generate the output: https://github.com/amithegde/LpDump
-
Anonymous commented
hii... all i would like to compile .cs file with out mail function can any one provide solution for it.......thanq advance
-
Lukas Bühler commented
Created a little project that tries to emulate the LinqPad Dump method:
https://github.com/lukebuehler/XhtmlDumper -
Alex commented
We created LinqPad nuget package for our dev group and tried to use Xhtml for the purpose of dumping entities during auditing and it works great, except there is a very big dependency from the whole LinqPad and Telerik has big performance issues in MVC project due to > ~500 types missing, so we have to switch to ObjectDumper class, so it would be beneficial if we could have render as Xhtml extracted into separate assembly or nuget package, happy to pay for that
-
Marc Lutz commented
@o.chantosa
CreateXhtmlWriter has an parameter maxDepth -
Bent Rasmussen commented
If this is your number one reason to use LINQPad, then it doesn't sound like a good reason for Joe to open-source it ;-)
-
Michael Nady commented
I need it for another scenario, I am using a generic list of a runtime object that maps exactly to a database table. and i need to look for a specific value inside it.
if you add linqPad as extension to visual studio, i can query this collection using linq (which is not permitted in the debugger!!), or i can dump its contents. -
Tormod commented
Yes, a dump method that returns formatted text resembling the output of LinqPad would be generally useful. If your problem is to get the code to compile within visual studio, just create your own stub.
-
Pat Kujawa commented
Well, here's one way to use it:
using System.Diagnostics;
using System.IO;public static class Extensions
{
/// <summary>
/// Dumps to a temporary html file and opens in the browser.
/// </summary>
/// <param name="o">The object to display.</param>
public static void Dump<T>(this T o)
{
string localUrl = Path.GetTempFileName() + ".html";
using (var writer = LINQPad.Util.CreateXhtmlWriter(true))
{
writer.Write(o);
File.WriteAllText(localUrl, writer.ToString());
}
Process.Start(localUrl);
}
} -
Pat Kujawa commented
Has anyone figured out how to get it to work when running unit tests? I am using Resharper's built-in testrunner, which has an HTML output window, but using CreateXhtmlWriter just dumps the HTML code (rather than rendering it).
-
robert.ivanc commented
So, I've went ahead and created a simple Visual Studio Debugger Visualizer which uses Linqpad Dump. You can find it at http://code.google.com/p/linqpadvisualizer/
I'll try to improve the serialization in the future, this is just a simple first try. :)
-
o.chantosa commented
how do you change the "maxDepth" when using the writer object created with CreateXhtmlWriter()? I am getting an "limit of graph" error in my output.
-
The latest RC lets you call CreateXhtmlWriter enabling dynamic expansion of results. Use of this feature ties you into IE, though - it doesn't seem to work properly with Firefox.
-
Pat Kujawa commented
Another reason for creating a LINQPad DLL (preferably without all the extra resources) is so that ClickOnce deployments can work correctly. In my case, referencing LINQPad.exe worked for development (and, I assume, installations), but I would get the following error when trying to use it with a ClickOnce deployment:
"Reference in the manifest does not match the identity of the downloaded assembly LINQPad.exe." -
Pat Kujawa commented
Using Joe and anunay's suggestions has worked well for me, but I notice that the resulting html doesn't include the javascript to allow expansion/shrinkage of different containers (a la LINQPad). I consider that ability very important, since it allows you to quickly focus on what you are interested in within the object. Is there a way to get this functionality into the Writer and for general use?
Also, I was wondering if there could be a way to isolate the Dump functionality without having to reference all of LINQPad - doing so increased my MSI from 600K to about 3200K :-(
Other than these issues, I am absolutely thrilled that I now have a quick, thorough tool for debugging/tracing!
-
anunay commented
Hi Joe
Thanks for exposing this functionally in the new Beta. Since I can't use Dump directly, I have created a new extension method Print as follows
static class Extension
{
public static string Print<T>(this T o)
{
var writer = LINQPad.Util.CreateXhtmlWriter();
writer.Write(o);
return writer.ToString();
}
}To view contents of any variable during debugging, I simply add myVariable.Print() to the watch window and use Visual Studios build in HTML visualizer to see formatted XHTML.
Thanks a ton
Anunay -
You can use LINQPad's XHTML Dump engine from within Visual Studio by adding a reference to LINQPad.exe and then doing this:
var writer = LINQPad.Util.CreateXhtmlWriter();
To call Dump(), simply call Write or WriteLine on the writer object.
When you want to view the output. call ToString() on the writer - if you write the output to a file, you can then view it in a web browser.