You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a type OneOf<T0, T1> where T0 (for example) is non-null value type (like int, or enum) and you deconstruct it then T1 will always get a non-null value.
To achieve the right semantic (where only one of the types should return a non-null value, like the discriminated-union type) you would need to convert T0 to a Nullable<T0>. Unfortunately this can only work value types (where T0: struct), so there's no easy solution that works with all cases.
If you have a type
OneOf<T0, T1>
whereT0
(for example) is non-null value type (likeint
, orenum
) and you deconstruct it then T1 will always get a non-null value.To achieve the right semantic (where only one of the types should return a non-null value, like the discriminated-union type) you would need to convert T0 to a
Nullable<T0>
. Unfortunately this can only work value types (where T0: struct
), so there's no easy solution that works with all cases.If you're interested please check my solution here: https://github.com/Drizin/OneOf.DeconstructorExtensions
The text was updated successfully, but these errors were encountered: