Open sync-by-unito[bot] opened 2 years ago
➤ papafe commented:
It seems that the only hard requirement to use the ModuleInitializer
attribute is to have at least C# 9.0, as it's a language feature. If the target code is using < .NET 5.0, we can define the attribute ourselves, and it will be treated in the same way, like discussed here: https://andrewlock.net/creating-a-source-generator-part-2-testing-an-incremental-generator-with-snapshot-testing/
Is there a way to detect the language version in SG? If so, then I think that'd be a nice approach.
Yes, we can do it. At the moment we check if the language version is too old for the nullable annotation.
At the moment we weave the module initializer to add all the weaved types to the types that need to be in the schema. If we want to move away from Fody probably we need to find an alternative approach. The most promising one is using the [ModuleInitializer] attribute, but that's available only from .NET 5 and C#9.
This would be a nice thing to have, but not necessary.