提交 bd0f55de 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #20632 from zaytsev-victor/Fixed20595

Fixed 'Generate Constructor' refactoring for an abstract class.
......@@ -637,7 +637,7 @@ public async Task TestGetter_Only_Auto_Props()
}",
@"abstract class Contribution
{
public Contribution(string title, int number)
protected Contribution(string title, int number)
{
Title = title;
Number = number;
......@@ -899,5 +899,26 @@ public void M()
public void N() { }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructorFromMembers)]
[WorkItem(20595, "https://github.com/dotnet/roslyn/issues/20595")]
public async Task ProtectedConstructorShouldBeGeneratedForAbstractClass()
{
await TestInRegularAndScriptAsync(
@"abstract class C
{
[|public int Prop { get; set; }|]
}",
@"abstract class C
{
protected C(int prop)
{
Prop = prop;
}
public int Prop { get; set; }
}",
options: Option(CodeStyleOptions.QualifyFieldAccess, CodeStyleOptions.TrueWithSuggestionEnforcement));
}
}
}
......@@ -556,7 +556,7 @@ Class Derived
End Class",
"MustInherit Class Base
Private x As Integer
Public Sub New(x As Integer)
Protected Sub New(x As Integer)
Me.x = x
End Sub
End Class
......
......@@ -83,7 +83,7 @@ internal static partial class ICodeDefinitionFactoryExtensions
var constructor = CodeGenerationSymbolFactory.CreateConstructorSymbol(
attributes: default,
accessibility: Accessibility.Public,
accessibility: containingTypeOpt.IsAbstractClass() ? Accessibility.Protected : Accessibility.Public,
modifiers: new DeclarationModifiers(),
typeName: typeName,
parameters: parameters,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册