Skip to content

Commit a9aa1e2

Browse files
author
msftbot[bot]
authored
Merge pull request #44819 from dotnet/merges/master-to-master-vs-deps
Merge master to master-vs-deps
2 parents 19df9a7 + b104b88 commit a9aa1e2

27 files changed

+1024
-749
lines changed

src/EditorFeatures/CSharpTest/GenerateConstructor/GenerateConstructorTests.cs

Lines changed: 274 additions & 7 deletions
Large diffs are not rendered by default.

src/EditorFeatures/VisualBasicTest/GenerateConstructor/GenerateConstructorTests.vb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,50 @@ End Class",
4444
End Class")
4545
End Function
4646

47+
<WorkItem(44537, "https://github.com/dotnet/roslyn/issues/44537")>
48+
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
49+
Public Async Function TestGenerateIntoContainingType_WithProperties() As Task
50+
Await TestInRegularAndScriptAsync(
51+
"Class C
52+
Sub Main()
53+
Dim f = New C([|4|], 5, 6)
54+
End Sub
55+
End Class",
56+
"Class C
57+
Public Sub New(v1 As Integer, v2 As Integer, v3 As Integer)
58+
Me.V1 = v1
59+
Me.V2 = v2
60+
Me.V3 = v3
61+
End Sub
62+
63+
Public ReadOnly Property V1 As Integer
64+
Public ReadOnly Property V2 As Integer
65+
Public ReadOnly Property V3 As Integer
66+
67+
Sub Main()
68+
Dim f = New C(4, 5, 6)
69+
End Sub
70+
End Class", index:=1)
71+
End Function
72+
73+
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
74+
Public Async Function TestGenerateIntoContainingType_NoMembers() As Task
75+
Await TestInRegularAndScriptAsync(
76+
"Class C
77+
Sub Main()
78+
Dim f = New C([|4|], 5, 6)
79+
End Sub
80+
End Class",
81+
"Class C
82+
Public Sub New(v1 As Integer, v2 As Integer, v3 As Integer)
83+
End Sub
84+
85+
Sub Main()
86+
Dim f = New C(4, 5, 6)
87+
End Sub
88+
End Class", index:=2)
89+
End Function
90+
4791
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
4892
Public Async Function TestInvokingFromInsideAnotherConstructor() As Task
4993
Await TestInRegularAndScriptAsync(

src/Features/CSharp/Portable/GenerateConstructor/CSharpGenerateConstructorService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected override ITypeSymbol GetAttributeArgumentType(
172172
protected override bool IsConversionImplicit(Compilation compilation, ITypeSymbol sourceType, ITypeSymbol targetType)
173173
=> compilation.ClassifyConversion(sourceType, targetType).IsImplicit;
174174

175-
internal override IMethodSymbol GetDelegatingConstructor(
175+
protected override IMethodSymbol GetDelegatingConstructor(
176176
State state,
177177
SemanticDocument document,
178178
int argumentCount,

src/Features/Core/Portable/FeaturesResources.resx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,6 @@ This version used in: {2}</value>
11291129
<data name="Convert_to_full_property" xml:space="preserve">
11301130
<value>Convert to full property</value>
11311131
</data>
1132-
<data name="Generate_constructor_in_0_without_fields" xml:space="preserve">
1133-
<value>Generate constructor in '{0}' (without fields)</value>
1134-
</data>
11351132
<data name="Warning_Method_overrides_symbol_from_metadata" xml:space="preserve">
11361133
<value>Warning: Method overrides symbol from metadata</value>
11371134
</data>
@@ -2768,4 +2765,10 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
27682765
<data name="Document_must_be_contained_in_the_workspace_that_created_this_service" xml:space="preserve">
27692766
<value>Document must be contained in the workspace that created this service</value>
27702767
</data>
2768+
<data name="Generate_constructor_in_0_with_fields" xml:space="preserve">
2769+
<value>Generate constructor in '{0}' (with fields)</value>
2770+
</data>
2771+
<data name="Generate_constructor_in_0_with_properties" xml:space="preserve">
2772+
<value>Generate constructor in '{0}' (with properties)</value>
2773+
</data>
27712774
</root>

src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.FieldDelegatingCodeAction.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System.Collections.Generic;
5+
using System.Collections.Immutable;
66
using System.Linq;
77
using System.Threading;
88
using System.Threading.Tasks;
@@ -42,11 +42,9 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
4242
//
4343
// Otherwise, just generate a normal constructor that assigns any provided
4444
// parameters into fields.
45-
var parameterToExistingFieldMap = new Dictionary<string, ISymbol>();
45+
var parameterToExistingFieldMap = ImmutableDictionary.CreateBuilder<string, ISymbol>();
4646
for (var i = 0; i < _state.Parameters.Length; i++)
47-
{
4847
parameterToExistingFieldMap[_state.Parameters[i].Name] = _state.SelectedMembers[i];
49-
}
5048

5149
var factory = _document.GetLanguageService<SyntaxGenerator>();
5250

@@ -55,15 +53,16 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
5553
var options = await _document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
5654
var preferThrowExpression = _service.PrefersThrowExpression(options);
5755

58-
var (fields, constructor) = factory.CreateFieldDelegatingConstructor(
56+
var members = factory.CreateMemberDelegatingConstructor(
5957
semanticModel,
6058
_state.ContainingType.Name,
6159
_state.ContainingType,
6260
_state.Parameters,
63-
parameterToExistingFieldMap,
64-
parameterToNewFieldMap: null,
61+
parameterToExistingFieldMap.ToImmutable(),
62+
parameterToNewMemberMap: null,
6563
addNullChecks: _addNullChecks,
66-
preferThrowExpression: preferThrowExpression);
64+
preferThrowExpression: preferThrowExpression,
65+
generateProperties: false);
6766

6867
// If the user has selected a set of members (i.e. TextSpan is not empty), then we will
6968
// choose the right location (i.e. null) to insert the constructor. However, if they're
@@ -76,7 +75,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
7675
var result = await CodeGenerator.AddMemberDeclarationsAsync(
7776
_document.Project.Solution,
7877
_state.ContainingType,
79-
fields.Concat(constructor),
78+
members,
8079
new CodeGenerationOptions(
8180
contextLocation: syntaxTree.GetLocation(_state.TextSpan),
8281
afterThisLocation: afterThisLocation),

src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.CodeAction.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)