Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,10 @@ private async Task ReplaceReferencesAsync(
editor.ReplaceNode(parent, parent.WithAdditionalAnnotations(
ConflictAnnotation.Create(FeaturesResources.Property_referenced_implicitly)));
}
else if (syntaxFacts.IsMemberInitializerNamedAssignmentIdentifier(parent))
{
editor.ReplaceNode(parent, parent.WithAdditionalAnnotations(
ConflictAnnotation.Create(FeaturesResources.Property_reference_cannot_be_updated)));
}
else if (syntaxFacts.IsNameOfSubpattern(parent))
else if (IsInNonUpdatableLocation(syntaxFacts, parent))
{
// If the property is in a location where it cannot be updated, then just
// replace it with a warning.
editor.ReplaceNode(parent, parent.WithAdditionalAnnotations(
ConflictAnnotation.Create(FeaturesResources.Property_reference_cannot_be_updated)));
}
Expand All @@ -284,6 +281,13 @@ await service.ReplaceReferenceAsync(
}
}
}

static bool IsInNonUpdatableLocation(ISyntaxFacts syntaxFacts, SyntaxNode parent)
{
return syntaxFacts.IsMemberInitializerNamedAssignmentIdentifier(parent) ||
syntaxFacts.IsNameOfSubpattern(parent) ||
syntaxFacts.IsInNamespaceOrTypeContext(parent);
}
}

private static async Task<Solution> ReplaceDefinitionsWithMethodsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Imports Microsoft.CodeAnalysis.ReplacePropertyWithMethods

Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeActions.ReplacePropertyWithMethods
<Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)>
Public Class ReplacePropertyWithMethodsTests
Public NotInheritable Class ReplacePropertyWithMethodsTests
Inherits AbstractVisualBasicCodeActionTest_NoEditor

Protected Overrides Function CreateCodeRefactoringProvider(workspace As TestWorkspace, parameters As TestParameters) As CodeRefactoringProvider
Expand Down Expand Up @@ -698,5 +698,24 @@ Class C
End Sub
End Class")
End Function

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/78642")>
Public Async Function TestPropertyNameReferencedInAsClause() As Task
Await TestInRegularAndScriptAsync(
"class C
property [||]Goo as Goo
end class",
"class C
Private _Goo As Goo

Public Function GetGoo() As Goo
Return _Goo
End Function

Public Sub SetGoo(AutoPropertyValue As Goo)
_Goo = AutoPropertyValue
End Sub
end class")
End Function
End Class
End Namespace
Loading