Replies: 1 comment
-
I downvoted on the first idea and the drawbacks in general. But I upvoted on the basic - though not concrete - idea of the |
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.
-
This is an attempt to generalized #147
Which I was seen it has benefit for an argument about
default
in #99Motivation
Sometimes we create custom type that can be in state that should not be used. One good example is
Fraction
structInitially this struct would made into 0/0. Which is NaN and not an initial value it should be used
So it more like this struct is inherently nullable struct by its own state. If we could treat it as
null value
then there would be helper operators (exist and will be exist) that could be reused. Especially??
and?.
Nullable Pattern
I suggest that we should have
INullable
interface to made a contract with all null related operatorBut it might be the same as
IEnumerable
that it would not really need to define type with this interface. Just implement the method with same name (but to have interface would prevent breaking change)I was using
Fraction
as an example but it could be class too. For example, disposable object such as unity'sGameObject
would also use this pattern for destroyed gameobjectAlternative
It would be easier if we could make it with static operator syntax
Related issue
#146,#147 Origin of this issue
also dotnet/roslyn#4347
#99 Motivation to solve problem about
default
struct and constructed structThis feature does not make us avoid uninitialized struct like #99 have argue. But it generalized a way we could explicitly know that an object of any types is in
undefined
state#34
??=
Would work well on this#36
!
operator could also work on this. Then it would need #99 and also solve #99 problem of initialize array of structBy explicitly use
!
it then preserve the original behaviourdrawback
This feature would be hard to let API consumer know that which struct could be nullable and which can't
other
I was mention a
default null value
above. Because I think we should be able to assign null value to this object if it is struct. And it would be that returned valueBeta Was this translation helpful? Give feedback.
All reactions