Skip to content
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

Support for value types #1

Open
Drizin opened this issue Aug 20, 2024 · 0 comments
Open

Support for value types #1

Drizin opened this issue Aug 20, 2024 · 0 comments

Comments

@Drizin
Copy link

Drizin commented Aug 20, 2024

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're interested please check my solution here: https://github.com/Drizin/OneOf.DeconstructorExtensions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant