dotnet / dotnet/roslyn

Fixing CS7036 (generate constructor based on base class) should give an option to use Primary Constructor

Open
#74,602 4 comments 1 reaction 0 assignees View on GitHub
Area-IDE help wanted
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

### Discussed in https://github.com/dotnet/roslyn/discussions/74598

Originally posted by **datvm** July 30, 2024
I am not sure if this is a duplicate because I think this is a very popular scenario. Assume we have this code:

```cs
class BaseClass(CancellationToken ct)
{

}

class DerivedClass : BaseClass
{
}
```

VS would suggest to "Generate constructor 'DerivedClass(ct)'":

![image](https://github.com/user-attachments/assets/de18aeba-e607-424a-a099-e32845a41b63)

After that, VS continues to suggest to use Primary Constructor instead which gives this code:

```cs
class DerivedClass(CancellationToken ct) : BaseClass(ct)
{
}
```

I think the analyzer should merge the two steps into one?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.