dotnet/roslyn

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

Open

#74.602 aperta il 30 lug 2024

Vedi su GitHub
 (4 commenti) (1 reazione) (0 assegnatari)C# (4257 fork)batch import
Area-IDEhelp wanted

Metriche repository

Star
 (20.414 star)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

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:

class BaseClass(CancellationToken ct)
{

}

class DerivedClass : BaseClass
{
}

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

image

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

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

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

Guida contributor