I am trying to evaluate an enum using FlagsAttribute as shown below. The problem is the ridiculous amount of code that it takes to ensure that the correct if statement is executed. I have four if statements that should only be executed if specific enumeration combinations are given, but nothing else :
- Private, static
- Private
- Privileged
- Public
Detecting the presence of the necessary flags is easy, but I must also ensure that no other flags are set, which are an absurd amount of code to enter and look like a maintenance nightmare.
[Flags]
public enum AccessModifierType : short
{
Infer = 1,
Public = 2,
Privileged = 4,
Private = 8,
Static = 16
}
Can someone rewrite this if statement more concisely?
if ((Model.CurrentContext.CurrentAccessModifierType & AccessModifierType.Public) == AccessModifierType.Public
&& (Model.CurrentContext.CurrentAccessModifierType & AccessModifierType.Static) != AccessModifierType.Static
&& (Model.CurrentContext.CurrentAccessModifierType & AccessModifierType.Privileged) != AccessModifierType.Privileged
&& (Model.CurrentContext.CurrentAccessModifierType & AccessModifierType.Private) != AccessModifierType.Private){
}