I'm a bit out of the loop with the latest features of the C# compiler, so I have to ask this:
Is there a way to get a compiler-generated member function that iterates over all defined and inherited properties of a class (at compile time, as opposed to at run-time by means of reflection) and returns a name-value dictionary?
class Foo
{
public string A { get; set; }
public string B { get; set; }
public string C { get; set; }
public string D { get; set; }
[Microsoft.CSharp._SomethingSomething_ToDictionaryConverter]
// Compiler-generated function:
// return new Dictionary<string, object>()
// {
// { nameof(Foo.A), this.A },
// { nameof(Foo.B), this.B },
// { nameof(Foo.C), this.C },
// { nameof(Foo.D), this.D },
// }
public Dictionary<string, object> ToDict();
}
// Then,
var foo = new Foo();
var d = foo.ToDict(); // yay!