Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate nullable reference types in public APIs #1067

Open
daniel-lerch opened this issue Aug 22, 2024 · 4 comments
Open

Annotate nullable reference types in public APIs #1067

daniel-lerch opened this issue Aug 22, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@daniel-lerch
Copy link

Is your feature request related to a problem? Please describe.
I just came across a NullReferenceException in my app which uses nullable reference types because I did not read MimeKit's documentation properly and missed that a type can be null.

Describe the solution you'd like
I consider nullable reference types a great feature of C# that makes you as a developer think twice whether you can really omit a null check. In my opinion it would be great if MimeKit would at least add nullable attributes to its public API. It might even make sense to enable nullable reference types for the entire code base.

Describe alternatives you've considered
N/A

Additional context
N/A

@jstedfast
Copy link
Owner

The problem is that I'm still trying to support .NET Framework which doesn't have this.

I'm not saying it can't be done, it's just a lot of work to #if/#else/#endif everything.

@jstedfast jstedfast added the enhancement New feature or request label Aug 22, 2024
@Sicos1977
Copy link

As far as I know this should work in .net framework. You probably have to upgrade to language version 8 or higher.

@daniel-lerch
Copy link
Author

daniel-lerch commented Aug 24, 2024

I can confirm that nullable reference types as such do work with .NET Framework. Some very useful attributes like [NotNullWhen] or [MemberNotNull] require .NET Standard 2.1 or .NET 5.0.

I enabled this feature for some classes in #1068 and added #if statements to add attributes for more modern .NET versions.

I would be willing to contribute further pull request to enable nullable reference types for more classes. Enabling for the entire project would be too much work at once for me, though.

@jstedfast
Copy link
Owner

FWIW, I created a new branch for this work. I also added compatibility attributes to reduce #if/#else's littering the codebase.

I just need to find time to work on it more, haha.

I wonder if I should look into writing a Roslyn-based tool to automate this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants