Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enumeration with FlagsAttributes

Tags:

c#

.net

enums

assume we have an enum that has FlagsAttribute.

[Flags]
enum CarOptions
{
  Sunroof = 1,
  Spoiler = 2,
  TintedWindow = 4
}

this could be used easily. now assume this one

[Flags]
enum CarOptions
{
  SunroofElectrical,
  SunroofMechanical,
  Spoiler,
  TintedWindowBlack,
  TintedWindowPurple
}

of course this is syntactically incorrect. but a Car can't have Mechanical and Electrical Sunroof at the same time or having Black and Purple TintedWindow both.
The question is: Is there a mechanism to implement the Flags enumeration which cannot have some attributes simultaneously?


1 Answers

I guess you would do this by using different enums for Sunroofs and TindedWindows.

like image 180
Alexander Schmidt Avatar answered Jul 14 '26 12:07

Alexander Schmidt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!