dotnet / dotnet/roslynator

Add analyzer for checking for null parameters on assignation

Open
#411 0 comments 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

It would be nice if you had an analyzer that would e.g. change

```cs
private string Arg1;
private Stream Arg2;

public void Foo(string arg1, Stream arg2)
{
this.Arg1 = arg1;
this.Arg2 = arg2;
}
```

to

```cs
private string Arg1;
private Stream Arg2;

public void Foo(string arg1, Stream arg2)
{
this.Arg1 = arg1 ?? throw new ArgumentNullException(nameof(arg1));
this.Arg2 = arg2 ?? throw new ArgumentNullException(nameof(arg2));
}
```

I think this should only be available when the line is a simple assignation (`x = param`).

Contributor guide

Open the contributing guide

Research direction

The issue provides no repository files or tests to start from. Locate existing C# analyzer and code-fix entry points and their tests, then verify how simple parameter-to-member assignments are diagnosed. Done means the analyzer offers null checks for those assignments while leaving other assignment forms unchanged.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.