VarDump is a utility for serialization runtime objects to C# and Visual Basic string.
$ dotnet add package VarDumpDeveloped as a free alternative of ObjectDumper.NET, which is not free for commercial use.
using System;
using VarDump;
var anonymousObject = new { Name = "Name", Surname = "Surname" };
var cs = new CSharpDumper().Dump(anonymousObject);
Console.WriteLine(cs);
var vb = new VisualBasicDumper().Dump(anonymousObject);
Console.WriteLine(vb);
using System;
using System.ComponentModel;
using VarDump;
using VarDump.Visitor;
var person = new Person { Name = "Nick", Age = 23 };
var dumpOptions = new DumpOptions { SortDirection = ListSortDirection.Ascending };
var csDumper = new CSharpDumper(dumpOptions);
var cs = csDumper.Dump(person);
var vbDumper = new VisualBasicDumper(dumpOptions);
var vb = vbDumper.Dump(person);
// C# string
Console.WriteLine(cs);
// VB string
Console.WriteLine(vb);
class Person
{
public string Name {get; set;}
public int Age {get; set;}
}
using System;
using System.Linq;
using VarDump.Extensions;
using VarDump.Visitor;
var dictionary = new[]
{
new
{
Name = "Name1",
Surname = "Surname1"
}
}.ToDictionary(x => x.Name, x => x);
Console.WriteLine(dictionary.Dump(DumpOptions.Default));using System;
using System.Linq;
using VarDump.Extensions;
using VarDump.Visitor;
VarDumpExtensions.VarDumpFactory = VarDumpFactories.VisualBasic;
var dictionary = new[]
{
new
{
Name = "Name1",
Surname = "Surname1"
}
}.ToDictionary(x => x.Name, x => x);
Console.WriteLine(dictionary.Dump(DumpOptions.Default));using System;
using System.Collections.Generic;
using VarDump;
using VarDump.Visitor;
using VarDump.Visitor.Descriptors;
// For more examples see https://github.com/ycherkes/VarDump/blob/main/test/VarDump.UnitTests/ObjectDescriptorMiddlewareSpec.cs
const string name = "World";
FormattableString formattableString = $"Hello, {name}";
var dumpOptions = new DumpOptions
{
Descriptors = { new FormattableStringMiddleware() }
};
var csDumper = new CSharpDumper(dumpOptions);
var cs = csDumper.Dump(formattableString);
var vbDumper = new VisualBasicDumper(dumpOptions);
var vb = vbDumper.Dump(formattableString);
// C# string
Console.WriteLine(cs);
// VB string
Console.WriteLine(vb);
class FormattableStringMiddleware : IObjectDescriptorMiddleware
{
public IEnumerable<IReflectionDescriptor> Describe(object @object, Type objectType, Func<IEnumerable<IReflectionDescriptor>> prev)
{
if (@object is FormattableString fs)
{
return Descriptor.FromObject(new
{
fs.Format,
Arguments = fs.GetArguments()
});
}
return prev();
}
}For more examples see Unit Tests
| Repository | License |
|---|---|
| Heavily customized version of System.CodeDom |
Privacy Notice: No personal data is collected at all.
This tool has been working well for my personal needs, but outside that its future depends on your feedback. Feel free to open an issue.
Any donations during this time will be directed to local charities at my own discretion.