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


C# INamedTypeSymbol.GetSymbolKey方法代码示例

本文整理汇总了C#中INamedTypeSymbol.GetSymbolKey方法的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol.GetSymbolKey方法的具体用法?C# INamedTypeSymbol.GetSymbolKey怎么用?C# INamedTypeSymbol.GetSymbolKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在INamedTypeSymbol的用法示例。


在下文中一共展示了INamedTypeSymbol.GetSymbolKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDependentTypesInProjectAsync

        private static async Task GetDependentTypesInProjectAsync(
            INamedTypeSymbol type, Project project, Solution solution, Func<INamedTypeSymbol, INamedTypeSymbol, bool> predicate, ConditionalWeakTable<Compilation, ConcurrentDictionary<SymbolKey, List<SymbolKey>>> cache, bool locationsInMetadata, ConcurrentSet<ISymbol> results, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

            var typeId = type.GetSymbolKey();

            List<SymbolKey> dependentTypeIds;
            if (!TryGetDependentTypes(cache, compilation, typeId, out dependentTypeIds))
            {
                List<INamedTypeSymbol> allTypes;
                if (locationsInMetadata)
                {
                    // From metadata, have to check other (non private) metadata types, as well as
                    // source types.
                    allTypes = GetAllSourceAndAccessibleTypesInCompilation(compilation, cancellationToken);
                }
                else
                {
                    // It's from source, so only other source types could derive from it.
                    allTypes = GetAllSourceTypesInCompilation(compilation, cancellationToken);
                }

                dependentTypeIds = new List<SymbolKey>();
                foreach (var t in allTypes)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (predicate(t, type))
                    {
                        dependentTypeIds.Add(t.GetSymbolKey());
                    }
                }

                dependentTypeIds = GetOrAddDependentTypes(cache, compilation, typeId, dependentTypeIds);
            }

            foreach (var id in dependentTypeIds)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var resolvedSymbols = id.Resolve(compilation, cancellationToken: cancellationToken).GetAllSymbols();
                foreach (var resolvedSymbol in resolvedSymbols)
                {
                    var mappedSymbol = await SymbolFinder.FindSourceDefinitionAsync(resolvedSymbol, solution, cancellationToken).ConfigureAwait(false) ?? resolvedSymbol;
                    results.Add(mappedSymbol);
                }
            }
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:51,代码来源:DependentTypeFinder.cs

示例2: GetUpdatedDocumentAsync

            public override async Task<Document> GetUpdatedDocumentAsync(
                    Document document,
                    IList<Tuple<INamedTypeSymbol, IList<ISymbol>>> unimplementedMembers,
                    INamedTypeSymbol classOrStructType,
                    SyntaxNode classOrStructDecl,
                    CancellationToken cancellationToken)
            {
                var result = document;
                var compilation = await result.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

                // Add an annotation to the type declaration node so that we can find it again to append the dispose pattern implementation below.
                result = await result.ReplaceNodeAsync(
                    classOrStructDecl,
                    classOrStructDecl.WithAdditionalAnnotations(s_implementingTypeAnnotation),
                    cancellationToken).ConfigureAwait(false);
                var root = await result.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
                classOrStructDecl = root.GetAnnotatedNodes(s_implementingTypeAnnotation).Single();
                compilation = await result.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
                classOrStructType = classOrStructType.GetSymbolKey().Resolve(compilation, cancellationToken: cancellationToken).Symbol as INamedTypeSymbol;

                // Use the code generation service to generate all unimplemented members except those that are
                // part of the dispose pattern. We can't use the code generation service to implement the dispose
                // pattern since the code generation service doesn't support injection of the custom boiler
                // plate code required for implementing the dispose pattern.
                var idisposable = TryGetSymbolForIDisposable(compilation);
                result = await base.GetUpdatedDocumentAsync(
                                            result,
                                            unimplementedMembers.Where(m => !m.Item1.Equals(idisposable)).ToList(),
                                            classOrStructType,
                                            classOrStructDecl,
                                            cancellationToken).ConfigureAwait(false);

                // Now append the dispose pattern implementation.
                root = await result.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
                classOrStructDecl = root.GetAnnotatedNodes(s_implementingTypeAnnotation).Single();
                compilation = await result.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
                classOrStructType = classOrStructType.GetSymbolKey().Resolve(compilation, cancellationToken: cancellationToken).Symbol as INamedTypeSymbol;
                result = Service.ImplementDisposePattern(result, root, classOrStructType, classOrStructDecl.SpanStart, Explicitly);

                // Remove the annotation since we don't need it anymore.
                root = await result.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
                classOrStructDecl = root.GetAnnotatedNodes(s_implementingTypeAnnotation).Single();
                result = await result.ReplaceNodeAsync(
                    classOrStructDecl,
                    classOrStructDecl.WithoutAnnotations(s_implementingTypeAnnotation),
                    cancellationToken).ConfigureAwait(false);

                return result;
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:49,代码来源:AbstractImplementInterfaceService.DisposePatternCodeAction.cs


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