M31.FluentAPI icon indicating copy to clipboard operation
M31.FluentAPI copied to clipboard

Use UnsafeAccessorAttribute in dotnet8 instead of reflection

Open Genmutant opened this issue 1 year ago • 2 comments

Would it be possible to generate private method accessors using UnsafeAccessorAttribute when targetting at least dotnet8? That would make it safe to use with NativeAOT and Trimming, as the accessed attributes are marked as used and not removed.

Genmutant avatar May 24 '24 13:05 Genmutant

Thank you for pointing this out! The UnsafeAccessorAttribute is indeed a great feature, and I would love to eliminate the reflection code. However, I plan to stick with .NET 6 until the end of the year, and I prefer not to complicate the code with conditional compilation directives (ifdefs).

Is there another way to address your issue? Are there possibilities for configuring the trimming, such as ignoring a specific class during the trimming process?

Best regards, Kevin

m31coding avatar May 26 '24 12:05 m31coding

Yes, it's possible to manually force it to keep the complete classes when trimming. I haven't checked if AOT would still work though.

Thanks for your fast answer and work!

Genmutant avatar May 26 '24 13:05 Genmutant