← All recipes
Moderne licensed

Use ArgumentNullException.ThrowIfNull()

Recipe IDOpenRewrite.Recipes.CSharp.Migration.Dotnet.Net6.UseThrowIfNullArtifactOpenRewrite.Recipes.CSharp.Migration.Dotnet

Replace if (x == null) throw new ArgumentNullException(nameof(x)) guard clauses with ArgumentNullException.ThrowIfNull(x) (CA1510). Handles == null, is null, reversed null ==, string literal param names, and braced then-blocks. Available since .NET 6.

Single recipemodernizationcsharpdotnetProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net6.UseThrowIfNull

If the recipe isn’t available locally, install it with:

mod config recipes nuget install OpenRewrite.Recipes.CSharp.Migration.Dotnet