Use ArgumentOutOfRangeException.ThrowIfNegative()

Proprietary

Replace if (value < 0) throw new ArgumentOutOfRangeException(nameof(value)) guard clauses with ArgumentOutOfRangeException.ThrowIfNegative(value). Also handles reversed 0 > value. Available since .NET 7.

OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net7.UseThrowIfNegative
mod run . --recipe=OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net7.UseThrowIfNegative

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.