VarDump 2.0.3

dotnet add package VarDump --version 2.0.3
                    
NuGet\Install-Package VarDump -Version 2.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VarDump" Version="2.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VarDump" Version="2.0.3" />
                    
Directory.Packages.props
<PackageReference Include="VarDump" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add VarDump --version 2.0.3
                    
#r "nuget: VarDump, 2.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package VarDump@2.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=VarDump&version=2.0.3
                    
Install as a Cake Addin
#tool nuget:?package=VarDump&version=2.0.3
                    
Install as a Cake Tool

Stand With Ukraine

VarDump

nuget version nuget downloads

VarDump turns runtime .NET objects into readable C# or Visual Basic source code.

Use it when you want copyable object initializers for tests, diagnostics, documentation, samples, or debugging workflows where plain text dumps are not enough.

dotnet add package VarDump

Quick Start

C# Source Output

This is the smallest useful VarDump example: create a dumper, pass any object, and print the generated source.

<p align="right"><a href="https://dotnetfiddle.net/vI6Wq4">Run .NET fiddle</a></p>

using System;
using VarDump;

var person = new
{
    Name = "Nick",
    Age = 23,
    Tags = new[] { "admin", "active" }
};

var source = new CSharpDumper().Dump(person);

Console.WriteLine(source);

Visual Basic Source Output

Use VisualBasicDumper when the output needs to be Visual Basic source.

using System;
using VarDump;

var person = new { Name = "Nick", Age = 23 };
var source = new VisualBasicDumper().Dump(person);

Console.WriteLine(source);

Core Features

VarDump is built for source-code output.

Feature Notes
C# and Visual Basic output Use CSharpDumper or VisualBasicDumper.
Complex collection support Anonymous collections, groups, lookups, read-only, immutable, frozen, and queryable collections.
Extended array support Includes multi-dimensional arrays and layout handling.
Date and time support Handles common .NET date/time types with configurable output style.
Numeric formatting Supports decimal, binary, hexadecimal, padding, and digit separators for integral values.
Output limits Cap collection size and traversal depth for large graphs.
Type name policy Choose short, nested-qualified, or fully qualified type names.
TextWriter output Stream output when you do not want to allocate one large string.

For behavior examples, see the unit tests.

Configure Output

Member Sorting And Skipped Values

Pass DumpOptions to either dumper to control member selection, sorting, formatting, collection layout, string literal style, and more.

<p align="right"><a href="https://dotnetfiddle.net/p4oIKX">Run .NET fiddle</a></p>

using System;
using System.ComponentModel;
using VarDump;
using VarDump.Visitor;

var options = new DumpOptions
{
    SortDirection = ListSortDirection.Ascending,
    IgnoreNullValues = false,
    IgnoreDefaultValues = false
};

var person = new { Name = "Nick", Age = 23, MiddleName = (string?)null };
var source = new CSharpDumper(options).Dump(person);

Console.WriteLine(source);

Full reference: DumpOptions API Guide.

Modern C# Literal Styles

Use literal style options when generated C# should target newer language features.

using VarDump;
using VarDump.Visitor;

var options = new DumpOptions
{
    StringLiteralStyle = StringLiteralStyle.Raw,
    CollectionLiteralStyle = CollectionLiteralStyle.Expression
};

var source = new CSharpDumper(options).Dump(new[] { "one", "two" });

Raw string literals require modern C# language support. Expression collection literals require C# 12 support.

Extension Methods

Install the separate extension package when you want DumpText(), DumpConsole(), DumpDebug(), or DumpTrace() on any object.

dotnet add package VarDump.Extensions

Object Extension Methods

<p align="right"><a href="https://dotnetfiddle.net/n9kjiF">Run .NET fiddle</a></p>

using System;
using System.Linq;

var dictionary = new[]
{
    new { Name = "Name1", Surname = "Surname1" }
}.ToDictionary(x => x.Name, x => x);

Console.WriteLine(dictionary.DumpText());
dictionary.DumpConsole();
dictionary.DumpDebug();
dictionary.DumpTrace();

Visual Basic Extension Output

<p align="right"><a href="https://dotnetfiddle.net/OGCcrk">Run .NET fiddle</a></p>

using System;
using System.Linq;

VarDumpExtensions.VarDumpFactory = VarDumpFactories.VisualBasic;

var dictionary = new[]
{
    new { Name = "Name1", Surname = "Surname1" }
}.ToDictionary(x => x.Name, x => x);

Console.WriteLine(dictionary.DumpText());

Advanced And Extensibility

Use the advanced APIs when you need to transform object descriptions before output or teach VarDump how to serialize a specific type.

Need Start here
Mask or rewrite member values before output Extensibility Guide: descriptor middleware
Add support for a known object type Extensibility Guide: known object visitors
Tune every output option DumpOptions API Guide
Compare behavior with ObjectDumper.NET Comparison fiddle

Comparison

VarDump grew out of work on Object Dumper Visual Studio, Visual Studio Code, and Rider extensions. It focuses on richer source-code generation options than ObjectDumper.NET.

Feature VarDump ObjectDumper
Console-style dump N/A Yes
Collections: anonymous, groups, lookups, read-only, immutable, frozen, queryable Yes No
Extended array support Yes No
Extended Date-Time support Yes No
Hex/Binary formatting and digit separator Yes No
Max collection size Yes N/A
Nested types Yes No
Output to TextWriter Yes No

Powered By

Repository License
Heavily customized version of System.CodeDom MIT

Privacy Notice: No personal data is collected.

This tool has been working well for my personal needs, but outside that its future depends on your feedback. Please open an issue with problems, ideas, or examples that should work better.

Sponsor the project on GitHub or PayPal.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on VarDump:

Package Downloads
VarDump.Extensions

Extension methods to simplify usage of the VarDump library.

Frank.Reflection.Dump

This is a library, (using the VarDump Nuget) that allows you to dump the contents of a type to a string as initilization code. This is helpful for debugging and logging, and can be used to generate code especially for unit tests.

Frank.LinqPad.VarDump

Frank's LINQPad VarDump extensions are a set of extensions to LINQPad that makes it easier to dump variables in LINQPad queries as initialized C# code.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on VarDump:

Repository Stars
ycherkes/ObjectDumper
A Visual Studio 2019-2026, Visual Studio Code and JetBrains Rider extension for exporting in-memory objects during debugging to C#, JSON, VB, XML, and YAML string.
Version Downloads Last Updated
2.0.3 37 6/29/2026
2.0.2 118 6/2/2026
2.0.1 111 6/1/2026
2.0.0 108 5/31/2026
1.0.6 2,237 6/19/2025
1.0.5.18 372 4/27/2025
1.0.5.17 854 12/16/2024
1.0.5.16 10,991 12/7/2024
1.0.5.15 884 10/23/2024
1.0.4.13 1,372 8/15/2024
1.0.4.12 338 6/8/2024
1.0.4.11 950 6/3/2024
Loading failed