Skip to main content
Source: Al0046UseGuardNotNullOrWhiteSpaceAnalyzer.cs

Description

Use Guard.NotNullOrWhiteSpace() instead of verbose null-or-whitespace check and throw patterns.

Bad Code

public void Process(string name)
{
    if (string.IsNullOrWhiteSpace(name))
        throw new ArgumentException("Cannot be null or whitespace", nameof(name));
}

Good Code

public void Process(string name)
{
    Guard.NotNullOrWhiteSpace(name);
}

Properties

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

Configuration

dotnet_diagnostic.AL0046.severity = warning