Diagnostics

edit

The package includes an analyzer. It validates the FastEnumAttribute declarations, and reports the System.Enum calls on the listed enums that have a generated equivalent. A code fix rewrites these calls, and adds the using directive of ExtensionMethodNamespace when it is needed.

IDSeverityTitle
MFEG0001ErrorFastEnum target type is invalid
MFEG0002WarningUse FastEnum Parse
MFEG0003WarningUse FastEnum TryParse
MFEG0004WarningUse FastEnum GetNames
MFEG0005WarningUse FastEnum GetValues
MFEG0006WarningUse FastEnum GetName
MFEG0007WarningUse FastEnum IsDefinedFast
MFEG0008WarningUse FastEnum ToStringFast
MFEG0009WarningFastEnum target enum has no members

MFEG0001: FastEnum target type is invalid

The type given to FastEnumAttribute is not an enum, or is null, for instance [assembly: FastEnumAttribute(typeof(string))]. Nothing is generated for it.

Fix: pass the type of an enum.

MFEG0002 to MFEG0008: Use the generated member

The code calls a System.Enum method on an enum listed in FastEnumAttribute, and the generator has written a faster equivalent:

IDCallReplacement
MFEG0002Enum.Parse(...)TEnum.Parse(...)
MFEG0003Enum.TryParse(...)TEnum.TryParse(...)
MFEG0004Enum.GetNames(...)TEnum.GetNames(useMetadata: false)
MFEG0005Enum.GetValues(...)TEnum.GetValues()
MFEG0006Enum.GetName(...)value.GetName()
MFEG0007Enum.IsDefined(...)TEnum.IsDefinedFast(...)
MFEG0008value.ToString()value.ToStringFast()

MFEG0002, MFEG0003, MFEG0004, MFEG0005 and MFEG0007 suggest static members, so they are reported only when the project uses C# 14 or later. The code fix is not offered when the replacement does not fit the call site, for instance when the array returned by Enum.GetNames is assigned to a string[] variable, which a ReadOnlySpan<string> cannot replace.

Fix: apply the code fix, or enable interceptors and suppress the rules, to keep the System.Enum calls and run the generated code anyway.

MFEG0009: FastEnum target enum has no members

The enum given to FastEnumAttribute declares no member. Nothing is generated for it, and the analyzer does not suggest generated members for it.

Fix: remove the attribute, or add members to the enum.