One important application of source generators today is bringing Native AOT support to libraries that map .NET types to programs. Examples of this include System.Text.Json, ConfigurationBinder, S.C.DataAnnotations, etc. A key constraint of the current crop of generators is that they only work with closed types -- for example having a source generated contract for type Foo
doesn't imply a source generated contract for List<Foo>
or other derivative types: Foo[]
, Dictionary<string, Foo>
, List<List<List<Foo>>>
, etc. These need to be configured explicitly.
The Serde.NET and PolyType libraries are experiments in building the next generation of .NET serialization. Both lean heavily on static abstracts but the missing ingredient in unlocking full-blown trait driven programming is extension interface implementations.
To give a more concrete example, let's consider a hypothetical inte