I’m of a blended mind on this. All of it sounds actually cool however I can’t assist however believe libraries that depend on source generators are simply not as good to utilize as reflection based libraries. Fix me if I’m incorrect, however all examples I have actually seen appear to depend on partial types and characteristics, while with reflection I do not need to utilize any characteristics normally and I have not typed the word
partial in years.
I have actually composed a lot of runtime code generation utilizing the Expressions API and it constantly seemed like having a cake and consuming it too; you can expose a stupidly easy public API with no extra event and lots of optional setup and * likewise * have the code run as quick as if you had actually composed it by hand. Things like start-up time have actually never ever been a limitation to me as most.NET code is (and I think will be) server-side code where that does not matter. The Expression API definitely has restrictions however, some construct are either extremely difficult to do (an easy foreach loop) or difficult (async).
Source generators are still fantastic however I sort of worry all libraries relocating to them that presently depend on runtime code generation while falling back in ergonomics. It likewise seems like an insufficient story, having the ability to include code based upon Roslyn parse trees is good, however not having the ability to reword code seems like a big missed out on chance to me. I see a lots of capacity for a build-time Roslyn analyzer sort of offer where like with a source generator you hook into the pipeline, however likewise have the capability to return a various tree than the one you got. Integrated with source generators this would produce an insane effective sort of macro system however without ever having any devoted macro syntax. You might simply set up the MyFancy.JSON plan and have this:
Serializer.Serialize<< Individual>>( individual, stream);.
Rewritten (however just as IL as this action lives prior to the compiler code generation) as:
Serializer.Serialize( individual, stream, PersonSerializer.Instance);.
Where the PersonSerializer circumstances is likewise created code that is all AOT friendly.
So a bit like PostSharp, other than built-in.