praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.03k stars 1.42k forks source link

Add trim/AOT annotations to make code trim/AOT-safe #1222

Open Sergio0694 opened 5 months ago

Sergio0694 commented 5 months ago

Closes #1218

This PR adds all trimming and AOT annotations to the code to make the codebase trim/AOT-safe. There's no functional changes introduced in this PR, other than removing the fast column accessor for all value types on NAOT, as that would otherwise throw (and generally just be unsupported code due to the AOT warning we'd have to suppress otherwise). It should still work, just take the slower reflection-based fallback path in that case. In order to allow all annotations to correctly flow to consumers, all projects have also been switched to multi-targeting, with the .NET 8 TFM being added as well.

mattleibow commented 5 months ago

To reduce all these changes and the sheer number of #if blocks, would it be worth adding these attribute types as internal types just for netstandard?

I have been doing for Skia and MAUI: https://github.com/mono/SkiaSharp/blob/main/source/Common/NullableAttributes.generated.cs

The attributes are ignored anyway on netstandard.

Sergio0694 commented 5 months ago

@mattleibow I thought about that (in fact I was just going to use PolySharp), but I decided not to because from my understanding SQLite-net also supports source-only mode. In that case if you were to define local attributes you could also get into weird situations if consumers already have polyfills for those (which is not uncommon), and you could get anything from warnings to build errors due to amboguous type references. Thoughts?

mattleibow commented 5 months ago

hmm, ok yeah, the source only mode will be more annoying. You could wrap the polyfills in a new #if !INCLUDE_POLY or something. But then if you are using plain netstd you will have to set this as well as if you have some of the items.

So yeah, I see the better choice really is these #if on each one.