Skip to main content
Source: Al0048UseGuardNotNegativeAnalyzer.cs

Description

Use Guard.NotNegative() instead of verbose negative-check and throw patterns.

Bad Code

public void SetCount(int count)
{
    if (count < 0)
        throw new ArgumentOutOfRangeException(nameof(count));
}

Good Code

public void SetCount(int count)
{
    Guard.NotNegative(count);
}

Properties

  • Category: Roslyn Utilities
  • Severity: Warning
  • Enabled by default: True
  • Code fix available: True

Configuration

dotnet_diagnostic.AL0048.severity = warning