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

Chapter 05. Storing a value using an enum type #84

Open
Dreamoochy opened this issue Jun 20, 2022 · 1 comment
Open

Chapter 05. Storing a value using an enum type #84

Dreamoochy opened this issue Jun 20, 2022 · 1 comment

Comments

@Dreamoochy
Copy link

After applying [System.Flags] to WondersOfTheAncientWorld enum, the class contains two fields of the same type:

public WondersOfTheAncientWorld FavouriteAncientWonder;
public WondersOfTheAncientWorld BucketList;

But FavouriteAncientWonder is designed to hold only one value, whereas with System.Flags it can contain multiple values like BucketList.

I realize this is just a synthetic example, but anyway IMHO each hmm... entity should only be allowed to serve its original purpose to avoid possible bugs and unexpected behaviour.

@markjprice
Copy link
Owner

I see what you mean. There is nothing to prevent someone from setting the FavoriteAncientWonder to a value that represents multiple wonders. It would be interesting to know how .NET APIs handle this. There are plenty of flags-type enums defined and there must be some scenarios where they must be used singularly. Or maybe not? I suppose if FavoriteAncientWonder was defined as a property then its setter could do some validation. I will do some research. Thanks for raising this interesting issue. :)

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

2 participants