dotnet / dotnet/roslynator

No analyzer/refactoring for throw expression?

Open
#442 1 comment 0 reactions 0 assignees View on GitHub
Area-Analyzers Feature Request
Dominant language
C#
Stars
3.5k
Forks
294
Avg merge
2h 30m
Merged PRs (30d)
4

Description

I have code as shown below:
```
if (value is Student student)
{
return student;
}

throw new ArgumentException("value must be of type Student", nameof(value));
```

I would like to have an analyzer to replace it with below (when the `Student` is reference type):
```
return value as Student ?? throw new ArgumentException("value must be of type Student", nameof(value));
```

Contributor guide

Open the contributing guide

Research direction

Use the two C# examples in the issue as the behavioral specification, then locate the analyzer/refactoring entry point in Roslynator. Confirm how existing analyzer tests are organized before implementing the transformation only when Student is a reference type. Done means the first form is offered as the requested throw-expression form and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.