ObjectDumper is a utility which aims to serialize C# objects to string for debugging and logging purposes.
This is a fork with some improvements (e.g. dumping of value types). This version is NOT available on NuGet!
Serialization, the process of converting a complex object to a machine-readable or over-the-wire transmittable string, is a technique often used in software engineering. A well-known serializer is Newtonsoft.JSON which serializes .NET objects to the data representation format JSON.
ObjectDumper.NET provides two excellent ways to visualize in-memory .NET objects:
- DumpStyle.Console: serialize objects to human-readable strings, often used to write complex C# objects to log files.
- DumpStyle.CSharp: serialize objects to C# initializer code, which can be used to compile a C# object again.
The following sample program uses DumpStyle.Console to write C# objects to the console output:
static void Main(string[] args)
{
var persons = new List<Person>
{
new Person { Name = "John", Age = 20, },
new Person { Name = "Thomas", Age = 30, },
};
var personsDump = ObjectDumper.Dump(persons);
Console.WriteLine(personsDump);
Console.ReadLine();
}
//CONSOLE OUTPUT:
{ObjectDumperSample.Netfx.Person}
Name: "John"
Age: 20
{ObjectDumperSample.Netfx.Person}
Name: "Thomas"
Age: 30
The following sample program uses DumpStyle.CSharp to write C# initializer code from in-memory to the console output:
static void Main(string[] args)
{
var persons = new List<Person>
{
new Person { Name = "John", Age = 20, },
new Person { Name = "Thomas", Age = 30, },
};
var personsDump = ObjectDumper.Dump(persons, DumpStyle.CSharp);
Console.WriteLine(personsDump);
Console.ReadLine();
}
//CONSOLE OUTPUT:
var listOfPersons = new List<Person>
{
new Person
{
Name = "John",
Age = 20
},
new Person
{
Name = "Thomas",
Age = 30
}
};
This project is Copyright © 2020 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.