-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Nullable Enable and Generics default #3471
Comments
agree it is frustrating; not much to do about it I think now though. Here is what I do:
|
You can see the full set of attributes that can inform nullable analysis here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/nullable-analysis. |
Tagging @jcouv for VS issue above. |
Is there a way to use the |
I think you might be able to declare the attributes as internal in the correct namespace within your assembly? I haven't tried because targeting .Net standard leaves too many warts for me to deal with so I gave up and multitarget just net48 and netcoreapp3.1. Hopefully net5/6+ will improve things and let me gain mono/uwp/xamarin/etc. runtime support before I actually need them. |
What about the situation where I need to deliver a nuget package that contains a public function with this attribute? |
The compiler is looking for an attribute on the type with the full name (no assembly though) of It isn't looking for a specific type. This is similar to how async works in earlier versions of .net framework. The internal attribute would have the same name. |
The original example is now legal in C# 9 public T? GetDefault<T>()
{
return default;
} |
After adding
<Nullable>enable</Nullable>
or#nullable enable
, I ran into the following problem with my Generic methods:This does not work:
This works with warning:
This works individually, but not together.
Logically, the first method should work.
What is the correct way out of this situation without creating several methods and suppressing warning?
P.S.
At the moment, I have not found anything better than this solution:
The text was updated successfully, but these errors were encountered: