roslyn: Generate Constructor should not copy "protected" from abstract base class

  1. CTRL+. on Abstract and choose Generate Constructor
public class Concrete : Abstract
{

}

public abstract class Abstract
{
    protected Abstract(string foo)
    {

    }
}

Expected:

public class Concrete : Abstract
{
    public Concrete(string foo) : base(foo)
    {
    }
}

public abstract class Abstract
{
    protected Abstract(string foo)
    {

    }
}

Actual:

public class Concrete : Abstract
{
    protected Concrete(string foo) : base(foo)
    {
    }
}

public abstract class Abstract
{
    protected Abstract(string foo)
    {

    }
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 29 (25 by maintainers)

Commits related to this issue

Most upvoted comments

I think we can change design to if base type is abstract and protected but derived type is not abstract but internal, then we put “internal” for ctor rather than “public”. otherwise, “public”?

🤔 If the class is internal, then the ctor is effectively internal anyway, so I’m not sure if that’s too useful.

I believe you meant here for fix?

http://source.roslyn.io/#Microsoft.CodeAnalysis.Features/GenerateMember/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.AbstractCodeAction.cs,62

and I agree. that looks like where we should make the fix.

the parameter name “constructor” is little bit confusing though. can you rename it to “baseConstructor” since that is the IMethodSymbol actually pointing to?

Hi, I’d like to work on the issue. It’s the first time for me in Open Source )