realm / realm-dotnet

Realm is a mobile database: a replacement for SQLite & ORMs
https://realm.io
Apache License 2.0
1.25k stars 163 forks source link

[SG] Evaluate alternatives to weaved module initializer #2948

Open sync-by-unito[bot] opened 2 years ago

sync-by-unito[bot] commented 2 years ago

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.

sync-by-unito[bot] commented 1 year 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/

nirinchev commented 1 year ago

Is there a way to detect the language version in SG? If so, then I think that'd be a nice approach.

papafe commented 11 months ago

Yes, we can do it. At the moment we check if the language version is too old for the nullable annotation.