Skip to content

Support single-line null checks for 'Add null check' #52385

@jnm2

Description

@jnm2

Version Used: VS 16.9.3

This is the most frequent ReSharper command that I use. Roslyn's code fix requires tedious cleanup because it generates five lines per parameter. The chances are not high that I'm going to start being okay with five lines per parameter. The contrast in friction is significant for me; with ReSharper, I'm not always cleaning up after I click.

using System;

public class C
{
    public void M(object first, object second, object third)
    {
        if (first is null)
        {
            throw new ArgumentNullException(nameof(first));
        }

        if (second is null)
        {
            throw new ArgumentNullException(nameof(second));
        }

        if (third is null)
        {
            throw new ArgumentNullException(nameof(third));
        }

        Console.WriteLine($"{first}: {second} ({third})");
    }
}

I want exactly what ReSharper does with a single command (except I have to insert the blank line myself, so Roslyn could even beat ReSharper here):

using System;

public class C
{
    public void M(object first, object second, object third)
    {
        if (first is null) throw new ArgumentNullException(nameof(first));
        if (second is null) throw new ArgumentNullException(nameof(second));
        if (third is null) throw new ArgumentNullException(nameof(third));

        Console.WriteLine($"{first}: {second} ({third})");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEConcept-Continuous ImprovementIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type

    Projects

    Status

    Complete

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions