Skip to content

Wrong enum type passed to HasFlag (CA2248)

Key dotnet.codequality.hasflag-wrong-enum · Severity warning · Category codequality

Microsoft analyzer CA2248. Flags Enum.HasFlag called with a value of a different enum type, which throws ArgumentException at run time.

if (permissions.HasFlag(FileAccess.Read)) // permissions is Permission
Open();
if (permissions.HasFlag(Permission.Read))
Open();