Mihail Shishkov
Mihail Shishkov

Reputation: 15887

Create new code refactoring for ReSharper

Is it possible to create a code refactoring for ReSharper like the one that checks a parameter for null.

enter image description here

This will generate the following guard check if we apply that to the method below

public void Method(string value)
{
     if (value == null) throw new ArgumentNullException(nameof(value));
}

Is it possible to create a refactoring like "Check string parameter for not null or white space" that will be suggested on string parameters only?

public void Method(string value)
{
    if (string.IsNullOrWhiteSpace(value)) throw new ArgumentNullException(nameof(value));
}

Upvotes: 1

Views: 41

Answers (1)

Matthias
Matthias

Reputation: 16209

That is possible using context action. I don't know with what exact version this was introduced, but at least with 2016.1 it should be there.

enter image description here

Besides that, you can use live templates for some needs. They have some limitations though. If you reach them, you can create a custom plugin that implements a context action for instance.

Upvotes: 2

Related Questions