Skip to main content
Source: Al0045UseGuardNotNullOrEmptyAnalyzer.cs

Description

Use Guard.NotNullOrEmpty() instead of verbose null-or-empty check and throw patterns. The guard helper is more concise and consistent.

Bad Code

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

Good Code

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

Properties

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

Configuration

dotnet_diagnostic.AL0045.severity = warning