Open
Description
public class AB { }
public enum ABEnum { A = 0, B = 1}
public class Test
{
public void TestAB()
{
foreach (var item in Enum.GetValues(typeof(AB))) // should warn here - syntactically valid C# but will blow up at run-time. Caused due to developer typing AB instead of ABEnum
{
Console.WriteLine(((Enum)item).GetDisplayName()); // Feature logged in: https://github.com/DotNetAnalyzers/ReflectionAnalyzers/issues/214
// ^^^^^^^^^^^^ bonus: don't raise Possible InvalidCastException if typeof(ABEnum) is an enum defined as an int64 sub-class (default scenario).
}
}
}
Metadata
Metadata
Assignees
Labels
No labels