-
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
NullableContextOptions and nullable generic type #2309
Comments
Yes, and?
The error message tells you exactly what's wrong and how to fix it.
The two cannot co-exist, so you have to specify either |
That said, you should see an additional attribute (along the lines of |
It could be useful to have the language automatically generate an overload for both cases when possible, though you'd probably want an additional attribute or keyword for that. |
I want CanBeNull generic type, both value types and reference types. Or can be add overload by where T : class and where T : struct |
@yaakov-h In my opinion T? should be always compiled to Nullable<T>, or at least there should be an option for users to opt-in such "strict nullable context". |
@hez2010 |
@yaakov-h |
@hez2010 see also: #2361 (comment) |
@hez2010 See also the by-now 4 year old decision that wrapper structs are a no-go:
|
I think what we really need is to separate types to nullable types and non-nullable types, but not the fake nullable type with a compile-time check. If The current nullable reference type implementation only does compile-time check and the only benefit is to prevent nullable types' spread in your own codes, which didn't solve the actual problem. I think breaking changes are must for it, otherwise the nullable reference type won't play the role it deserves. And for competible consideration, the feature can be designed to a feature that needs to be opt-in manually by users. |
Relates to #2194 |
Closing as implemented in C# 9 |
The text was updated successfully, but these errors were encountered: