Description
UseGuard.DefinedEnum() instead of verbose enum-validation and throw patterns.
Bad Code
Good Code
Properties
- Category: Roslyn Utilities
- Severity: Warning
- Enabled by default: True
- Code fix available: True
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Use Guard.DefinedEnum() instead of verbose if (!Enum.IsDefined) throw patterns
Guard.DefinedEnum() instead of verbose enum-validation and throw patterns.
public void SetStatus(Status status)
{
if (!Enum.IsDefined(typeof(Status), status))
throw new ArgumentOutOfRangeException(nameof(status));
}
public void SetStatus(Status status)
{
Guard.DefinedEnum(status);
}
dotnet_diagnostic.AL0051.severity = warning
Was this page helpful?
