Aller au contenu

Wrong enum type passed to HasFlag (CA2248)

Ce contenu n’est pas encore disponible dans votre langue.

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();