Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the LINQPad Dump() extension method in Visual Studio? [closed]

Tags:

c#

linqpad

LINQPad is amazing, and particularly useful is the Dump() extension methods which renders objects and structs of almost any type, anonymous or not, to the console.

Initially, when I moved to Visual Studio 2010, I tried to make my own Dump method using a delegate to get the values to render for anonymous types, etc. It's getting pretty complicated though and while it was fun and educational at first, I need a solid implementation. Having checked out the LINQPad code in .NET Reflector I am even more assured that I'm not going to get the implementation right.

Is there a free library I can include to provide the Dump functionality?

like image 772
gav Avatar asked Apr 23 '10 14:04

gav


People also ask

How do I open LINQPad in Visual Studio?

Right-click your project in Visual Studio -> Add Reference -> Browse to the exe binary file location, typically found in its install directory C:\Program Files\LINQPad\ --> select LINQPad.exe . Once done, then you can add a "using directive" for it in your file: using System.

What is Dump in LINQPad?

LINQPad is amazing, and particularly useful is the Dump() extension methods which renders objects and structs of almost any type, anonymous or not, to the console.

What is Dump () in C#?

A dump is a file that contains a snapshot of the process at the time it was created and can be useful for examining the state of your application. Dumps can be used to debug your .

What is LINQPad used for?

LINQPad is a software utility targeted at . NET Framework and . NET Core development. It is used to interactively query SQL databases (among other data sources such as OData or WCF Data Services) using LINQ, as well as interactively writing C# code without the need for an IDE.


2 Answers

I wrote an extension method to Object that uses the Json.Net serializer with the pretty format option. JSON is easy enough to read when formatted like that. You miss type info, but I don't know that you need that, especially considering how easy this is. Hasn't failed me yet. I use Json.Net and not MS' because it has the capability of handling circular references in complex graphs, where MS' cannot, or didn't at the time I thought of it.

using Newtonsoft.Json;  public static class Dumper {     public static string ToPrettyString(this object value)     {          return JsonConvert.SerializeObject(value, Formatting.Indented);     }      public static T Dump<T>(this T value)     {         Console.WriteLine(value.ToPrettyString());         return value;     } } 
like image 186
Chad Ruppert Avatar answered Sep 23 '22 19:09

Chad Ruppert


Look here (your path may vary):

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

like image 35
Raj Kaimal Avatar answered Sep 26 '22 19:09

Raj Kaimal