Skip to main content
Source: Al0049UseGuardPositiveAnalyzer.cs

Description

Use Guard.Positive() instead of verbose positive-check and throw patterns.

Bad Code

public void SetPageSize(int size)
{
    if (size <= 0)
        throw new ArgumentOutOfRangeException(nameof(size));
}

Good Code

public void SetPageSize(int size)
{
    Guard.Positive(size);
}

Properties

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

Configuration

dotnet_diagnostic.AL0049.severity = warning