提交 009255b4 编写于 作者: C CyrusNajmabadi

Merge pull request #11468 from CyrusNajmabadi/vbGenerateMethod

Properly generate a method off of a property in VB.
......@@ -2232,6 +2232,52 @@ End Namespace
</text>.Value.Replace(vbLf, vbCrLf))
End Function
<WorkItem(11461, "https://github.com/dotnet/roslyn/issues/11461")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)>
Public Async Function TestGenerateMethodOffOfExistingProperty() As Task
Await TestAsync(
<text>
Imports System
Public NotInheritable Class Repository
Shared ReadOnly Property agreementtype As AgreementType
Get
End Get
End Property
End Class
Public Class Agreementtype
End Class
Class C
Shared Sub TestError()
[|Repository.AgreementType.NewFunction|]("", "")
End Sub
End Class
</text>.Value.Replace(vbLf, vbCrLf),
<text>
Imports System
Public NotInheritable Class Repository
Shared ReadOnly Property agreementtype As AgreementType
Get
End Get
End Property
End Class
Public Class Agreementtype
Friend Sub NewFunction(v1 As String, v2 As String)
Throw New NotImplementedException()
End Sub
End Class
Class C
Shared Sub TestError()
Repository.AgreementType.NewFunction("", "")
End Sub
End Class</text>.Value.Replace(vbLf, vbCrLf))
End Function
Public Class GenerateConversionTests
Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest
......
......@@ -43,6 +43,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateMethod
End Function
Protected Overrides Function IsCandidate(node As SyntaxNode, token As SyntaxToken, diagnostic As Diagnostic) As Boolean
' If we have a diagnostic on "a.b.c" in something like a.b.c(...), then don't try to
' perform fixes on 'a' or 'a.b'.
Dim diagnosticSpan = diagnostic.Location.SourceSpan
If node.Span.Start = diagnosticSpan.Start AndAlso node.Span.End < diagnosticSpan.End Then
Return False
End If
Return TypeOf node Is QualifiedNameSyntax OrElse
TypeOf node Is SimpleNameSyntax OrElse
TypeOf node Is MemberAccessExpressionSyntax OrElse
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册