【发布时间】:2017-10-26 08:48:46
【问题描述】:
我正在尝试使用来自 Rolyn 的一些私有代码来实现代码修复
Partial Public Class SynatxEditorFixAllProvider
Inherits FixAllProvider
Public Overrides Async Function GetFixAsync(ByVal fixAllContext As FixAllContext) As Task(Of CodeAction)
Dim documentsAndDiagnosticsToFixMap As ImmutableDictionary(Of Document, ImmutableArray(Of Diagnostic)) = Await fixAllContext.GetDocumentDiagnosticsToFixAsync().ConfigureAwait(False)
Return Await GetFixAsync1(documentsAndDiagnosticsToFixMap, fixAllContext, fixAllContext.CancellationToken).ConfigureAwait(False)
End Function
Async Function GetFixAsync1(ByVal documentsAndDiagnosticsToFixMap As ImmutableDictionary(Of Document, ImmutableArray(Of Diagnostic)), ByVal _FixAllContext As FixAllContext, ByVal cancellationToken As CancellationToken) As Task(Of CodeAction)
' Process all documents in parallel.
Dim updatedDocumentTasks As IEnumerable(Of Task(Of Document)) = documentsAndDiagnosticsToFixMap.Select(Function(kvp) FixDocumentAsync(kvp.Key, kvp.Value, cancellationToken))
Await Task.WhenAll(updatedDocumentTasks).ConfigureAwait(False)
Dim currentSolution As Solution = _FixAllContext.Solution
For Each Task As Task(Of Document) In updatedDocumentTasks
' 'await' the tasks so that if any completed in a canceled manner then we'll
' throw the right exception here. Calling .Result on the tasks might end up
' with AggregateExceptions being thrown instead.
Dim updatedDocument As Document = Await Task.ConfigureAwait(False)
currentSolution = currentSolution.WithDocumentSyntaxRoot(updatedDocument.Id, Await updatedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False))
Next Task
Dim title As String = GetFixAllTitle(_FixAllContext)
Return New SolutionChangeAction(title, Function(underscore) Task.FromResult(currentSolution))
End Function
只有这段代码我得到一个错误,它需要下面的代码
Partial Public MustInherit Class SynatxEditorFixAllProvider
Protected MustOverride Function FixAllAsync(ByVal document As Document, ByVal diagnostics As ImmutableArray(Of Diagnostic), ByVal editor As SyntaxEditor, ByVal cancellationToken As CancellationToken) As Task
End Class
但是如果我在下面一行上面添加代码就会出错,
"New 不能用于声明为 MustInherit 的类"
Public Shared ReadOnly Property Instance() As FixAllProvider = New SynatxEditorFixAllProvider()
【问题讨论】:
-
这三者之间没有“对”。
New初始化一个对象的新实例,MustInherit表示这是一个只能被其他类继承的基类(即你不能创建它的实例,除非它被继承),MustOverride表示必须“重写”属性或方法(即不能按原样使用它,必须先在继承基类的类中重写它)。
标签: vb.net roslyn-code-analysis