Why would you ever allow an Optional<T?> #269
Unanswered
jezzsantos
asked this question in
Q&A
Replies: 1 comment
-
It can. notnull constraint can be applied to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am wondering why you would intend anyone to define an
Optional<DateTime?>
orOptional<string?>
orOptional<MyClass?>
orOptional<MyEnum>
, and forbid nullable types.Then interpret
new Optional<DateTime>(deafult(DateTime)) as as actually being
None`.Obviously, I know that value types cannot be null (and reference type can be null), but the class offer whatever contract it likes.
So, maybe this is a design philosophy question? rather than a strictly csharp question.
I would have thought, from a usability perspective the contract of this class would be better if it did not allow nullable types as
T
.Perhaps C# cannot enforce/prevent that, so we have to deal with it regardless? or we use reflection to verify that.
Can anyone offer insight?
Beta Was this translation helpful? Give feedback.
All reactions