Skip to content

[Analyzer Proposal]: Convert argument null checks to ArgumentNullException.ThrowIfNull #68326

@stephentoub

Description

@stephentoub

In support of the now-defunct !! feature, @RikkiGibson built into a Roslyn an analyzer/fixer that found constructs like:

void M(string arg)
{
    if (arg is null)
        throw new ArgumentNullException(arg);
    ...
}

and replaced them with:

void M(string arg!!)
{
    ...
}

Now that !! is no more, we should salvage this work and transform it to instead use ArgumentNullException.ThrowIfNull if available:

void M(string arg)
{
    ArgumentNullException.ThrowIfNull(arg);
    ...
}

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Threadingcode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions