All rules
CA1511Maintainability Enabled by default: As suggestion

Use ArgumentException throw helper

Use ArgumentException throw helper

Microsoft docs

Description

Argument checks have a substantial impact on code size and often dominate the code for small functions and property setters. These checks prevent inlining and cause substantial instruction-cache pollution. Throw-helper methods such as System.ArgumentException.ThrowIfNullOrEmpty(System.String,System.String) are simpler and more efficient than if blocks that construct a new exception instance.

Cause

Code checks whether an argument is null or an empty string and then conditionally throws an System.ArgumentException.

How to fix violations

Replace the if block that throws the exception with a call to System.ArgumentException.ThrowIfNullOrEmpty(System.String,System.String). Or, in Visual Studio, use the lightbulb menu to fix your code automatically.

Example

void M(string arg)
{
    if (string.IsNullOrEmpty(arg))
        throw new ArgumentException("", "arg");
}

void M(string arg)
{
    ArgumentException.ThrowIfNullOrEmpty(arg);
}

When to suppress

It's safe to suppress a violation of this rule if you're not concerned about the maintainability of your code. It is also fine to suppress violations that are identified to be false positives.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0