本文整理汇总了C#中Compilation.WithEventQueue方法的典型用法代码示例。如果您正苦于以下问题:C# Compilation.WithEventQueue方法的具体用法?C# Compilation.WithEventQueue怎么用?C# Compilation.WithEventQueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compilation
的用法示例。
在下文中一共展示了Compilation.WithEventQueue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAndAttachToCompilation
// internal for testing purposes
internal static AnalyzerDriver CreateAndAttachToCompilation(
Compilation compilation,
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerOptions options,
AnalyzerManager analyzerManager,
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
bool reportAnalyzer,
out Compilation newCompilation,
CancellationToken cancellationToken)
{
AnalyzerDriver analyzerDriver = compilation.AnalyzerForLanguage(analyzers, analyzerManager);
newCompilation = compilation.WithEventQueue(new AsyncQueue<CompilationEvent>());
var categorizeDiagnostics = false;
var analysisOptions = new CompilationWithAnalyzersOptions(options, onAnalyzerException, concurrentAnalysis: true, logAnalyzerExecutionTime: reportAnalyzer);
analyzerDriver.Initialize(newCompilation, analysisOptions, categorizeDiagnostics, cancellationToken);
var analysisScope = new AnalysisScope(newCompilation, analyzers, concurrentAnalysis: newCompilation.Options.ConcurrentBuild, categorizeDiagnostics: categorizeDiagnostics);
analyzerDriver.AttachQueueAndStartProcessingEvents(newCompilation.EventQueue, analysisScope, cancellationToken: cancellationToken);
return analyzerDriver;
}
示例2: CompilationWithAnalyzers
private CompilationWithAnalyzers(Compilation compilation, ImmutableArray<DiagnosticAnalyzer> analyzers, CompilationWithAnalyzersOptions analysisOptions, CancellationToken cancellationToken)
{
VerifyArguments(compilation, analyzers, analysisOptions);
_compilation = compilation.WithEventQueue(new AsyncQueue<CompilationEvent>());
_analyzers = analyzers;
_analysisOptions = analysisOptions;
_cancellationToken = cancellationToken;
_analysisState = new AnalysisState(analyzers);
_analysisResult = new AnalysisResult(analysisOptions.LogAnalyzerExecutionTime, analyzers);
_driverPool = new ObjectPool<AnalyzerDriver>(() => compilation.AnalyzerForLanguage(analyzers, AnalyzerManager.Instance));
_executingConcurrentTreeTasksOpt = analysisOptions.ConcurrentAnalysis ? new Dictionary<SyntaxTree, Tuple<Task, CancellationTokenSource>>() : null;
_concurrentTreeTaskTokensOpt = analysisOptions.ConcurrentAnalysis ? new Dictionary<Task, int>() : null;
_executingCompilationOrNonConcurrentTreeTask = null;
}
示例3: AttachAnalyzerDriverToCompilation
internal static Compilation AttachAnalyzerDriverToCompilation(Compilation compilation, ImmutableArray<IDiagnosticAnalyzer> analyzers, out AnalyzerDriver analyzerDriver3, AnalyzerOptions options, CancellationToken cancellationToken)
{
analyzerDriver3 = compilation.AnalyzerForLanguage(analyzers, options, cancellationToken);
return compilation.WithEventQueue(analyzerDriver3.CompilationEventQueue);
}
示例4: Create
// internal for testing purposes
internal static AnalyzerDriver Create(
Compilation compilation,
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerOptions options,
AnalyzerManager analyzerManager,
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
out Compilation newCompilation,
CancellationToken cancellationToken)
{
options = options ?? AnalyzerOptions.Empty;
AnalyzerDriver analyzerDriver = compilation.AnalyzerForLanguage(analyzers, analyzerManager, cancellationToken);
newCompilation = compilation.WithEventQueue(analyzerDriver.CompilationEventQueue);
var addDiagnostic = GetDiagnosticSinkWithSuppression(analyzerDriver.DiagnosticQueue.Enqueue, newCompilation);
Action<Exception, DiagnosticAnalyzer, Diagnostic> newOnAnalyzerException;
if (onAnalyzerException != null)
{
// Wrap onAnalyzerException to pass in filtered diagnostic.
var comp = newCompilation;
newOnAnalyzerException = (ex, analyzer, diagnostic) =>
onAnalyzerException(ex, analyzer, GetFilteredDiagnostic(diagnostic, comp));
}
else
{
// Add exception diagnostic to regular diagnostic bag.
newOnAnalyzerException = (ex, analyzer, diagnostic) => addDiagnostic(diagnostic);
}
// Assume all analyzers are non-thread safe.
var singleThreadedAnalyzerToGateMap = ImmutableDictionary.CreateRange(analyzers.Select(a => KeyValuePair.Create(a, new object())));
var analyzerExecutor = AnalyzerExecutor.Create(newCompilation, options, addDiagnostic, newOnAnalyzerException, IsCompilerAnalyzer, analyzerManager, singleThreadedAnalyzerToGateMap, cancellationToken);
analyzerDriver.Initialize(newCompilation, analyzerExecutor, cancellationToken);
return analyzerDriver;
}
示例5: Create
// internal for testing purposes
internal static AnalyzerDriver Create(Compilation compilation, ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerOptions options, out Compilation newCompilation, Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException, CancellationToken cancellationToken)
{
options = options ?? AnalyzerOptions.Empty;
AnalyzerDriver analyzerDriver = compilation.AnalyzerForLanguage(analyzers, options, continueOnAnalyzerException, cancellationToken);
newCompilation = compilation.WithEventQueue(analyzerDriver.CompilationEventQueue);
analyzerDriver.Initialize(newCompilation, cancellationToken);
return analyzerDriver;
}
示例6: Create
// internal for testing purposes
internal static AnalyzerDriver Create(
Compilation compilation,
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerOptions options,
AnalyzerManager analyzerManager,
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
bool reportAnalyzer,
out Compilation newCompilation,
CancellationToken cancellationToken)
{
options = options ?? AnalyzerOptions.Empty;
AnalyzerDriver analyzerDriver = compilation.AnalyzerForLanguage(analyzers, analyzerManager, cancellationToken);
newCompilation = compilation.WithEventQueue(analyzerDriver.CompilationEventQueue);
var addDiagnostic = GetDiagnosticSinkWithSuppression(analyzerDriver.DiagnosticQueue.Enqueue, newCompilation);
Action<Exception, DiagnosticAnalyzer, Diagnostic> newOnAnalyzerException;
if (onAnalyzerException != null)
{
// Wrap onAnalyzerException to pass in filtered diagnostic.
var comp = newCompilation;
newOnAnalyzerException = (ex, analyzer, diagnostic) =>
onAnalyzerException(ex, analyzer, GetFilteredDiagnostic(diagnostic, comp));
}
else
{
// Add exception diagnostic to regular diagnostic bag.
newOnAnalyzerException = (ex, analyzer, diagnostic) => addDiagnostic(diagnostic);
}
// Assume all analyzers are non-thread safe.
var singleThreadedAnalyzerToGateMap = ImmutableDictionary.CreateRange(analyzers.Select(a => KeyValuePair.Create(a, new object())));
if (reportAnalyzer)
{
// If we are reporting detailed analyzer performance numbers, then do a dummy invocation of Compilation.GetTypeByMetadataName API upfront.
// This API seems to cause a severe hit for the first analyzer invoking it and hence introduces lot of noise in the computed analyzer execution times.
var unused = newCompilation.GetTypeByMetadataName("System.Object");
}
Func<DiagnosticAnalyzer, object> getAnalyzerGate = analyzer => singleThreadedAnalyzerToGateMap[analyzer];
var analyzerExecutor = AnalyzerExecutor.Create(newCompilation, options, addDiagnostic, newOnAnalyzerException, IsCompilerAnalyzer, analyzerManager, getAnalyzerGate, reportAnalyzer, cancellationToken);
analyzerDriver.Initialize(newCompilation, analyzerExecutor, cancellationToken);
return analyzerDriver;
}