当前位置: 首页>>代码示例>>C#>>正文


C# ConcurrentBag.ToImmutableSortedSet方法代码示例

本文整理汇总了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]));
                                }
                            }
                        });
                });
        }
开发者ID:morrisjoe,项目名称:roslyn-analyzers,代码行数:53,代码来源:TypeNamesShouldNotMatchNamespaces.cs


注:本文中的ConcurrentBag.ToImmutableSortedSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。