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


C# SyntaxNode.WithAdditionalAnnotations方法代码示例

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


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

示例1: CreateSymbolToDeclarationAnnotationMap

        private Dictionary<ISymbol, SyntaxAnnotation> CreateSymbolToDeclarationAnnotationMap(
            IEnumerable<ISymbol> includedMembers,
            ref Solution solution,
            out List<DocumentId> documentIds,
            SyntaxNode typeNode,
            out SyntaxAnnotation typeNodeAnnotation,
            CancellationToken cancellationToken)
        {
            var symbolToDeclarationAnnotationMap = new Dictionary<ISymbol, SyntaxAnnotation>();
            var currentRoots = new Dictionary<SyntaxTree, SyntaxNode>();
            documentIds = new List<DocumentId>();

            var typeNodeRoot = typeNode.SyntaxTree.GetRoot(CancellationToken.None);
            typeNodeAnnotation = new SyntaxAnnotation();
            currentRoots[typeNode.SyntaxTree] = typeNodeRoot.ReplaceNode(typeNode, typeNode.WithAdditionalAnnotations(typeNodeAnnotation));
            documentIds.Add(solution.GetDocument(typeNode.SyntaxTree).Id);

            foreach (var includedMember in includedMembers)
            {
                var location = includedMember.Locations.Single();
                var tree = location.SourceTree;

                SyntaxNode root;
                if (!currentRoots.TryGetValue(tree, out root))
                {
                    root = tree.GetRoot(cancellationToken);
                    documentIds.Add(solution.GetDocument(tree).Id);
                }

                var token = root.FindToken(location.SourceSpan.Start);

                var annotation = new SyntaxAnnotation();
                symbolToDeclarationAnnotationMap.Add(includedMember, annotation);
                currentRoots[tree] = root.ReplaceToken(token, token.WithAdditionalAnnotations(annotation));
            }

            foreach (var root in currentRoots)
            {
                var document = solution.GetDocument(root.Key);
                solution = solution.WithDocumentSyntaxRoot(document.Id, root.Value, PreservationMode.PreserveIdentity);
            }

            return symbolToDeclarationAnnotationMap;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:44,代码来源:AbstractExtractInterfaceService.cs

示例2: Visit

            public override SyntaxNode Visit(SyntaxNode node)
            {
                if (node == _contextNode)
                {
                    _seenContextNode = true;

                    // Annotate the context node so we can find it again in the new tree
                    // after we've added the close curly.
                    return node.WithAdditionalAnnotations(s_annotation);
                }

                // rewrite this node normally.
                var rewritten = base.Visit(node);
                if (rewritten == node)
                {
                    return rewritten;
                }

                // This node changed.  That means that something underneath us got
                // rewritten.  (i.e. we added the annotation to the context node).
                Debug.Assert(_seenContextNode);

                // Ok, we're past the context node now.  See if this is a node with 
                // curlies.  If so, if it has a missing close curly then add in the 
                // missing curly.  Also, even if it doesn't have missing curlies, 
                // then still ask to format its close curly to make sure all the 
                // curlies up the stack are properly formatted.
                var braces = rewritten.GetBraces();
                if (braces.Item1.Kind() == SyntaxKind.None && 
                    braces.Item2.Kind() == SyntaxKind.None)
                {
                    // Not an item with braces.  Just pass it up.
                    return rewritten;
                }

                // See if the close brace is missing.  If it's the first missing one 
                // we're seeing then definitely add it.
                if (braces.Item2.IsMissing)
                {
                    if (!_addedFirstCloseCurly)
                    {
                        var closeBrace = SyntaxFactory.Token(SyntaxKind.CloseBraceToken)
                            .WithAdditionalAnnotations(Formatter.Annotation);
                        rewritten = rewritten.ReplaceToken(braces.Item2, closeBrace);
                        _addedFirstCloseCurly = true;
                    }
                }
                else
                {
                    // Ask for the close brace to be formatted so that all the braces
                    // up the spine are in the right location.
                    rewritten = rewritten.ReplaceToken(braces.Item2,
                        braces.Item2.WithAdditionalAnnotations(Formatter.Annotation));
                }

                return rewritten;
            }
开发者ID:genlu,项目名称:roslyn,代码行数:57,代码来源:CSharpSyntaxFactsService.cs


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