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.
$ dotnet add package Frank.Reflection.DumpInitially a slimmed down "fork" of Namotion.Refection, (also MIT licensed), but it is evolving into something else.
dotnet add package Frank.Reflection
var name = typeof(Person).GetDisplayName();
var hasProperty = typeof(Person).HasProperty("Name");
var person = new Person { Name = "Bill" };
var hasValue = person.TryGetPropertyValue<T>("Name", out var value);
if (hasValue)
{
Console.WriteLine(value);
}
A library to dump types to a string that is compilable into a new type. This is useful for generating code from types, for example when generating code for a collection of suppliers to use in a test.
var type = typeof(Persons);
var dump = type.DumpClass();
namespace GeneratedCode;
public static class GeneratedPerson
{
public static Person Get()
{
return new Person
{
Name = "Frank",
Age = 30,
Address = new Address
{
Street = "Street",
Number = 1
}
};
}
}