Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06f095f

Browse files
Update 'use auto property' to respect user options aroundthis. for property access. (#79405)
2 parents24ab192 +b7159b0 commit06f095f

File tree

17 files changed

+218
-146
lines changed

17 files changed

+218
-146
lines changed

‎src/Analyzers/CSharp/Tests/UseAutoProperty/UseAutoPropertyTests.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
usingSystem.Threading.Tasks;
66
usingMicrosoft.CodeAnalysis.CodeFixes;
7+
usingMicrosoft.CodeAnalysis.CodeStyle;
78
usingMicrosoft.CodeAnalysis.CSharp;
89
usingMicrosoft.CodeAnalysis.CSharp.Test.Utilities;
910
usingMicrosoft.CodeAnalysis.CSharp.UseAutoProperty;
@@ -2999,4 +3000,62 @@ class Class
29993000
readonly ref int P => ref i;
30003001
}
30013002
""");
3003+
3004+
[Fact,WorkItem("https://github.com/dotnet/roslyn/issues/77011")]
3005+
publicTaskTestRemoveThisIfPreferredCodeStyle()
3006+
=>TestInRegularAndScriptAsync(
3007+
"""
3008+
class C
3009+
{
3010+
[|private readonly string a;|]
3011+
3012+
public C(string a)
3013+
{
3014+
this.a = a;
3015+
}
3016+
3017+
public string A => a;
3018+
}
3019+
""",
3020+
"""
3021+
class C
3022+
{
3023+
public C(string a)
3024+
{
3025+
A = a;
3026+
}
3027+
3028+
public string A { get; }
3029+
}
3030+
""",
3031+
options:Option(CodeStyleOptions2.QualifyPropertyAccess,false,NotificationOption2.Error));
3032+
3033+
[Fact,WorkItem("https://github.com/dotnet/roslyn/issues/77011")]
3034+
publicTaskTestKeepThisIfPreferredCodeStyle()
3035+
=>TestInRegularAndScriptAsync(
3036+
"""
3037+
class C
3038+
{
3039+
[|private readonly string a;|]
3040+
3041+
public C(string a)
3042+
{
3043+
this.a = a;
3044+
}
3045+
3046+
public string A => a;
3047+
}
3048+
""",
3049+
"""
3050+
class C
3051+
{
3052+
public C(string a)
3053+
{
3054+
this.A = a;
3055+
}
3056+
3057+
public string A { get; }
3058+
}
3059+
""",
3060+
options:Option(CodeStyleOptions2.QualifyPropertyAccess,true,NotificationOption2.Error));
30023061
}

‎src/EditorFeatures/Core/InlineRename/AbstractEditorInlineRenameService.InlineRenameLocationSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task<IInlineRenameReplacementInfo> GetReplacementsAsync(
4444
CancellationTokencancellationToken)
4545
{
4646
varconflicts=await_renameLocationSet.ResolveConflictsAsync(
47-
_renameInfo.RenameSymbol,_renameInfo.GetFinalSymbolName(replacementText),nonConflictSymbolKeys:default,cancellationToken).ConfigureAwait(false);
47+
_renameInfo.RenameSymbol,_renameInfo.GetFinalSymbolName(replacementText),cancellationToken).ConfigureAwait(false);
4848

4949
returnnewInlineRenameReplacementInfo(conflicts);
5050
}

‎src/EditorFeatures/Test2/Diagnostics/UseAutoProperty/UseAutoPropertyTests.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ partial class C
131131

132132
publicC()
133133
{
134-
this.P=0;
134+
P=0;
135135
}
136136
}".Trim()
137137

‎src/EditorFeatures/Test2/Rename/RenameEngineResult.vb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,13 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename
136136
Dimlocations=Renamer.FindRenameLocationsAsync(
137137
solution,symbol,renameOptions,CancellationToken.None).GetAwaiter().GetResult()
138138

139-
Returnlocations.ResolveConflictsAsync(symbol,renameTo,nonConflictSymbolKeys:=Nothing,CancellationToken.None).GetAwaiter().GetResult()
139+
Returnlocations.ResolveConflictsAsync(symbol,renameTo,CancellationToken.None).GetAwaiter().GetResult()
140140
Else
141141
' This tests that rename properly works when the entire call is remoted to OOP and the final result is
142142
' marshaled back.
143143

144144
ReturnRenamer.RenameSymbolAsync(
145-
solution,symbol,renameTo,renameOptions,
146-
nonConflictSymbolKeys:=Nothing,CancellationToken.None).GetAwaiter().GetResult()
145+
solution,symbol,renameTo,renameOptions,CancellationToken.None).GetAwaiter().GetResult()
147146
EndIf
148147
EndFunction
149148

‎src/Features/CSharp/Portable/UseAutoProperty/CSharpUseAutoPropertyCodeFixProvider.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
usingMicrosoft.CodeAnalysis.CSharp.Extensions;
1515
usingMicrosoft.CodeAnalysis.CSharp.Syntax;
1616
usingMicrosoft.CodeAnalysis.Editing;
17+
usingMicrosoft.CodeAnalysis.FindSymbols;
1718
usingMicrosoft.CodeAnalysis.Formatting;
1819
usingMicrosoft.CodeAnalysis.Formatting.Rules;
1920
usingMicrosoft.CodeAnalysis.PooledObjects;
20-
usingMicrosoft.CodeAnalysis.Rename;
2121
usingMicrosoft.CodeAnalysis.Shared.Extensions;
2222
usingMicrosoft.CodeAnalysis.UseAutoProperty;
2323
usingRoslyn.Utilities;
@@ -59,16 +59,15 @@ protected override SyntaxNode GetNodeToRemove(VariableDeclaratorSyntax declarato
5959

6060
protectedoverridePropertyDeclarationSyntaxRewriteFieldReferencesInProperty(
6161
PropertyDeclarationSyntaxproperty,
62-
LightweightRenameLocationsfieldLocations,
62+
ImmutableArray<ReferencedSymbol>fieldLocations,
6363
CancellationTokencancellationToken)
6464
{
6565
// We're going to walk this property body, converting most reference of the field to use the `field` keyword
6666
// instead. However, not all reference can be updated. For example, reference through another instance. Those
6767
// we update to point at the property instead. So we grab that property name here to use in the rewriter.
6868
varpropertyIdentifierName=IdentifierName(property.Identifier.WithoutTrivia());
6969

70-
varidentifierNames=fieldLocations.Locations
71-
.Select(loc=>loc.Location.FindNode(getInnermostNodeForTie:true,cancellationToken)asIdentifierNameSyntax)
70+
varidentifierNames=fieldLocations.SelectMany(loc=>loc.Locations.Select(loc=>loc.Location.FindNode(getInnermostNodeForTie:true,cancellationToken)asIdentifierNameSyntax))
7271
.WhereNotNull()
7372
.ToSet();
7473

‎src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ private static async Task<Solution> RenameAsync(
287287
// edit the files in the current project
288288
varresolution=awaitinitialLocations
289289
.Filter((documentId,span)=>!linkedProjectIds.Contains(documentId.ProjectId)&&filter(documentId,span))
290-
.ResolveConflictsAsync(field,finalName,nonConflictSymbolKeys:default,cancellationToken).ConfigureAwait(false);
290+
.ResolveConflictsAsync(field,finalName,cancellationToken).ConfigureAwait(false);
291291

292292
Contract.ThrowIfFalse(resolution.IsSuccessful);
293293

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp