Hey, is there a way to keep negative flags in C #? For example, I have the following flag enumeration that represents some styles:
[Flags] public enum Styles { Default = 0, Bold = 1, Italic = 2 }
Now I have several objects to which these styles can be applied, and then all the related ones are combined (i.e. another object can inherit some previously set styles). In addition to this, I would like to define negative flags that basically override the inherited styles. Therefore, if the style was previously set to Styles.Bold | Styles.Italic Styles.Bold | Styles.Italic , and the object inherits this style, but has a negative Styles.Bold flag, then the result should be just Styles.Italic .
Is there any mechanism that already does this? I basically, although with two methods: first defines NotXY enum values, which are then somehow analyzed to exclude XY values if they are set.
The other is simply the definition of two fields, positive and negative flags, where negative flags are specifically defined in the optional field, and I get the resulting flags by simply doing positiveFlags ^ negativeFlags .
edit:
If this is not clear, I need to save each of these styles of intermediate objects. So it can be, for example, like this:
object1: Default object2: Bold object3: -Bold Italic
And if object3 also inherits the values 1 and 2, the end result should just be Italic .
Another example is in response to a question from Cyrene Johnston, and in my statement in a comment that negative values apply only at the current level:
1: Bold 2: -Bold -Italic 3: Italic
2 eliminates both bold and italics from previous objects, but then should not be applied further (positive values should be), so the final value will be Italic again.