本文整理汇总了C#中ConcurrentBag.ToImmutableSortedSet方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.ToImmutableSortedSet方法的具体用法?C# ConcurrentBag.ToImmutableSortedSet怎么用?C# ConcurrentBag.ToImmutableSortedSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentBag
的用法示例。
在下文中一共展示了ConcurrentBag.ToImmutableSortedSet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public override void Initialize(AnalysisContext analysisContext)
{
analysisContext.EnableConcurrentExecution();
analysisContext.RegisterCompilationStartAction(
compilationStartAnalysisContext =>
{
var namedTypesInCompilation = new ConcurrentBag<INamedTypeSymbol>();
compilationStartAnalysisContext.RegisterSymbolAction(
symbolAnalysisContext =>
{
var namedType = (INamedTypeSymbol)symbolAnalysisContext.Symbol;
namedTypesInCompilation.Add(namedType);
}, SymbolKind.NamedType);
compilationStartAnalysisContext.RegisterCompilationEndAction(
compilationAnalysisContext =>
{
var namespaceNamesInCompilation = new ConcurrentBag<string>();
var compilation = compilationAnalysisContext.Compilation;
AddNamespacesFromCompilation(namespaceNamesInCompilation, compilation.GlobalNamespace);
/* We construct a dictionary whose keys are all the components of all the namespace names in the compilation,
* and whose values are the namespace names of which the components are a part. For example, if the compilation
* includes namespaces A.B and C.D, the dictionary will map "A" to "A", "B" to "A.B", "C" to "C", and "D" to "C.D".
* When the analyzer encounters a type name that appears in a dictionary, it will emit a diagnostic, for instance,
* "Type name "D" conflicts with namespace name "C.D"".
* A component can occur in more than one namespace (for example, you might have namespaces "A" and "A.B".).
* In that case, we have to choose one namespace to report the diagnostic on. We want to make sure that this is
* deterministic (we don't want to complain about "A" in one compilation, and about "A.B" in the next).
* By calling ToImmutableSortedSet on the list of namespace names in the compilation, we ensure that
* we'll always construct the dictionary with the same set of keys.
*/
var namespaceComponentToNamespaceNameDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
UpdateNamespaceTable(namespaceComponentToNamespaceNameDictionary, namespaceNamesInCompilation.ToImmutableSortedSet());
InitializeWellKnownSystemNamespaceTable();
foreach (var symbol in namedTypesInCompilation)
{
var symbolName = symbol.Name;
if (s_wellKnownSystemNamespaceTable.ContainsKey(symbolName))
{
compilationAnalysisContext.ReportDiagnostic(symbol.CreateDiagnostic(SystemRule, symbolName, s_wellKnownSystemNamespaceTable[symbolName]));
}
else if (namespaceComponentToNamespaceNameDictionary.ContainsKey(symbolName))
{
compilationAnalysisContext.ReportDiagnostic(symbol.CreateDiagnostic(DefaultRule, symbolName, namespaceComponentToNamespaceNameDictionary[symbolName]));
}
}
});
});
}