UnitsNet icon indicating copy to clipboard operation
UnitsNet copied to clipboard

Use C#8 nullable reference types

Open angularsen opened this issue 5 years ago • 4 comments

C#8 is due in the fall of 2019 and one interesting feature we can take advantage of is nullable reference types, instead of JetBrains' [NotNull] and [CanBeNull] attributes that don't really give much value to the consumers of the library.

With nullable reference types I believe we can communicate to consumers whether a returned object can be null or not. We use struct value types for all quantities today so I'm not sure how much impact it will make, but we are discussing moving to class instead and at that point it will probably give a lot more value.

Anyway, it's a cool new language feature and if anyone wants to do a PR to play with it, this can be a good start. If no one else does, I'll probably take a stab at it sometime.

angularsen avatar Aug 09 '19 19:08 angularsen

I'm looking at using Nullable Reference Types as well. From what I understand though it's a compiler only thing. It will not validate at runtime. So it's only usable at compile time with static analysis.

ebfortin avatar Aug 16 '19 14:08 ebfortin

Yes that's right. It only has an effect at compile time. Also, it is an optional feature that consumers of the nuget will have to enable in their projects to benefit from. Still, the idea of communicating nullability to nuget consumers is pretty great.

angularsen avatar Aug 16 '19 15:08 angularsen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 15 '19 15:10 stale[bot]

Keeping this one up for a bit in case someone wants to pick it up and run with it.

angularsen avatar Oct 25 '19 07:10 angularsen