本文整理汇总了C#中Builder.ToResult方法的典型用法代码示例。如果您正苦于以下问题:C# Builder.ToResult方法的具体用法?C# Builder.ToResult怎么用?C# Builder.ToResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder.ToResult方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeAsync
public static async Task<CompilerAnalysisResult> AnalyzeAsync(this CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken)
{
var version = await DiagnosticIncrementalAnalyzer.GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
// PERF: Run all analyzers at once using the new GetAnalysisResultAsync API.
var analysisResult = await analyzerDriver.GetAnalysisResultAsync(cancellationToken).ConfigureAwait(false);
var analyzers = analyzerDriver.Analyzers;
var compilation = analyzerDriver.Compilation;
var builder = ImmutableDictionary.CreateBuilder<DiagnosticAnalyzer, AnalysisResult>();
foreach (var analyzer in analyzers)
{
var result = new Builder(project, version);
foreach (var tree in compilation.SyntaxTrees)
{
ImmutableDictionary<DiagnosticAnalyzer, ImmutableArray<Diagnostic>> syntaxDiagnosticsByAnalyzer;
ImmutableArray<Diagnostic> syntaxDiagnostics;
if (analysisResult.SyntaxDiagnostics.TryGetValue(tree, out syntaxDiagnosticsByAnalyzer) &&
syntaxDiagnosticsByAnalyzer.TryGetValue(analyzer, out syntaxDiagnostics))
{
Contract.Requires(syntaxDiagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(syntaxDiagnostics, analyzerDriver.Compilation).Count());
result.AddSyntaxDiagnostics(tree, syntaxDiagnostics);
}
ImmutableDictionary<DiagnosticAnalyzer, ImmutableArray<Diagnostic>> semanticDiagnosticsByAnalyzer;
ImmutableArray<Diagnostic> semanticDiagnostics;
if (analysisResult.SemanticDiagnostics.TryGetValue(tree, out semanticDiagnosticsByAnalyzer) &&
semanticDiagnosticsByAnalyzer.TryGetValue(analyzer, out semanticDiagnostics))
{
Contract.Requires(semanticDiagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(semanticDiagnostics, analyzerDriver.Compilation).Count());
result.AddSemanticDiagnostics(tree, semanticDiagnostics);
}
}
ImmutableArray<Diagnostic> compilationDiagnostics;
if (analysisResult.CompilationDiagnostics.TryGetValue(analyzer, out compilationDiagnostics))
{
Contract.Requires(compilationDiagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(compilationDiagnostics, analyzerDriver.Compilation).Count());
result.AddCompilationDiagnostics(compilationDiagnostics);
}
builder.Add(analyzer, result.ToResult());
}
return new CompilerAnalysisResult(builder.ToImmutable(), analysisResult.AnalyzerTelemetryInfo);
}
示例2: AnalyzeAsync
public static async Task<ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult>> AnalyzeAsync(this CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken)
{
var version = await DiagnosticIncrementalAnalyzer.GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
// Run all analyzers at once.
// REVIEW: why there are 2 different cancellation token? one that I can give to constructor and one I can give in to each method?
// REVIEW: we drop all those allocations for the diagnostics returned. can we avoid this?
await analyzerDriver.GetAnalyzerDiagnosticsAsync(cancellationToken).ConfigureAwait(false);
// this is wierd, but now we iterate through each analyzer for each tree to get cached result.
// REVIEW: no better way to do this?
var noSpanFilter = default(TextSpan?);
var analyzers = analyzerDriver.Analyzers;
var compilation = analyzerDriver.Compilation;
var builder = ImmutableDictionary.CreateBuilder<DiagnosticAnalyzer, AnalysisResult>();
foreach (var analyzer in analyzers)
{
var result = new Builder(project, version);
// REVIEW: more unnecessary allocations just to get diagnostics per analyzer
var oneAnalyzers = ImmutableArray.Create(analyzer);
foreach (var tree in compilation.SyntaxTrees)
{
var model = compilation.GetSemanticModel(tree);
var syntax = await analyzerDriver.GetAnalyzerSyntaxDiagnosticsAsync(tree, oneAnalyzers, cancellationToken).ConfigureAwait(false);
Contract.Requires(syntax.Count() == CompilationWithAnalyzers.GetEffectiveDiagnostics(syntax, analyzerDriver.Compilation).Count());
result.AddSyntaxDiagnostics(tree, syntax);
var semantic = await analyzerDriver.GetAnalyzerSemanticDiagnosticsAsync(model, noSpanFilter, oneAnalyzers, cancellationToken).ConfigureAwait(false);
Contract.Requires(semantic.Count() == CompilationWithAnalyzers.GetEffectiveDiagnostics(semantic, analyzerDriver.Compilation).Count());
result.AddSemanticDiagnostics(tree, semantic);
}
var rest = await analyzerDriver.GetAnalyzerCompilationDiagnosticsAsync(oneAnalyzers, cancellationToken).ConfigureAwait(false);
Contract.Requires(rest.Count() == CompilationWithAnalyzers.GetEffectiveDiagnostics(rest, analyzerDriver.Compilation).Count());
result.AddCompilationDiagnostics(rest);
builder.Add(analyzer, result.ToResult());
}
return builder.ToImmutable();
}