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 VarDumpThis is the smallest useful VarDump example: create a dumper, pass any object, and print the generated source.
using System;
using VarDump;
var person = new
{
Name = "Nick",
Age = 23,
Tags = new[] { "admin", "active" }
};
var source = new CSharpDumper().Dump(person);
Console.WriteLine(source);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);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.
Pass DumpOptions to either dumper to control member selection, sorting, formatting, collection layout, string literal style, and more.
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.
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.
Install the separate extension package when you want DumpText(), DumpConsole(), DumpDebug(), or DumpTrace() on any object.
dotnet add package VarDump.Extensionsusing 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();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());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 |
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 |
| Repository | License |
|---|---|
| Heavily customized version of System.CodeDom |
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.