Type aliases that cannot be assigned to other types than itself or it's basetype. #8139
Unanswered
thargol1
asked this question in
Language Ideas
Replies: 3 comments 17 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Opaque type aliases in C# is something we want since the last ice age |
Beta Was this translation helpful? Give feedback.
0 replies
-
You will be able to do that with the |
Beta Was this translation helpful? Give feedback.
17 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.
-
proposed syntax
workings
Using explicit is a compiler only instruction that prohibits assignments to or from those types other than from the type itself or it's base type.
These assignments are ok
These assigments generate a compiler error:
These function calls generate a compiler error:
Why
Many key-like types in applications are either string or integral type. Preventing those types from accidentily be assigned to each other could prevent errors during compile time.
I tried solutions like value structs. But they require a lot of extra code to make them work with JSON or EF.
Lowering
This should be a compiler only function.
Lowers to
Beta Was this translation helpful? Give feedback.
All reactions