Repository navigation
[Proposal]: Data-carrying enums #10379
Replies: 8 comments 46 replies
|
In mixed-data example, On case numbering. A simple idea is to do case numbering if and only if the data-carrying |
|
it must be on the table. |
|
Thoughts on allowing omitting |
|
We can consider to utilize the |
|
Enum has been a named integer data type up until now, and I think it would be confusing to change it to be a data storage type. |
|
I'm slightly concerned by the fact that enum classes and structs support being open and closed. That strongly suggests that, given public enum class Foo
{ Bar, Baz } it's somehow possible to declare a case of the Foo enum outside its definition, which is... a choice. I know that being open-by-default is a better fit with existing C#, but i get the feeling that 99.999% of these enums are going to be closed and the extra keyword is going to become quite the irritation. |
|
I love the idea of this feature, but don't like usage of |
public readonly partial closed enum record struct Foo { }Too liberal? Please fix union non-boxing. that's all |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Data-carrying enums
An alternate approach builds discriminated unions on C#'s existing
unionfeature.Summary
Bring discriminated unions to C# through named cases that can carry data. The
enum classandenum structforms provide reference-type and value-type representations with record-like case behavior and enum-style construction withoutnew.Supporting Documents
The directory overview maps the supporting documents:
enum structthat avoids boxing during construction and extraction.This is the community discussion for the proposal; LDM design work is tracked in the champion issue.
All reactions