This analyzer includes the Bluehill.EnumExtensionsAttribute
attribute and a corresponding source generator for generating ToStringFast and HasFlagFast extension methods for enumerations. For performance and AOT compatibility, should use ToStringFast() or HasFlagFast() extension methods instead. See the EnumExtensionsGenerator page for more details.
This rule is reported if there is already a ToStringFast() or HasFlagFast() extension method for that enumeration.
This rule is reported when the enumeration does not have the Bluehill.EnumExtensionsAttribute and the ToString() or HasFlag() method is called. Note: This is not reported if the project being called is different from the project of the enumeration (if the enumeration is in an external assembly). It is also not reported if the enumeration is a nested type and is not public or internal accessible.
public enum TestEnum {
A,
B,
C
}
public class TestClass {
public void TestMethod() {
var e = TestEnum.A;
var str = e.ToString();
var hasFlag = e.HasFlag(TestEnum.B);
}
}
[Bluehill.EnumExtensions]
public enum TestEnum {
A,
B,
C
}
public class TestClass {
public void TestMethod() {
var e = TestEnum.A;
var str = e.ToStringFast();
var hasFlag = e.HasFlagFast(TestEnum.B);
}
}