The enum type passed as an argument to the HasFlag
method call is different from the calling enum type.
The Enum.HasFlag
method expects the enum
argument to be of the same enum
type as the instance on which the method is invoked. If these are different enum
types, an unhandled exception will be thrown at run time.
To fix violations, use the same enum type on both the argument and the caller:
public class C
{
[Flags]
public enum MyEnum { A, B, }
[Flags]
public enum OtherEnum { A, }
public void Method(MyEnum m)
{
m.HasFlag(OtherEnum.A); // Enum types are different, this call will cause an `ArgumentException` to be thrown at run time
m.HasFlag(MyEnum.A); // Valid call
}
}
When to suppress warnings
Do not suppress violations from this rule.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4