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


C# SyntaxNode.ReplaceTrivia方法代码示例

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


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

示例1: ReplaceTabWithFourSpacesAsync

 private Task<Document> ReplaceTabWithFourSpacesAsync(Document document, SyntaxNode root, SyntaxTrivia tabTrivia
     , CancellationToken cancellationToken)
 {
     SyntaxTrivia fourSpacesTrivia = SyntaxFactory.Whitespace(new string(' ', 4 * tabTrivia.Span.Length));
     SyntaxNode newRoot = root.ReplaceTrivia(tabTrivia, fourSpacesTrivia);
     return Task.FromResult(document.WithSyntaxRoot(newRoot));
 }
开发者ID:RickyLin,项目名称:CodingConventionsCop,代码行数:7,代码来源:IndentWithFourSpacesCodeFixProvider.cs

示例2: RemoveImproperDocumentationTrivia

 private static SyntaxNode RemoveImproperDocumentationTrivia(SyntaxNode node)
 {
     IEnumerable<SyntaxTrivia> commentTrivia = from t in node.DescendantTrivia()
                                               where t.Kind() == SyntaxKind.DocumentationCommentTrivia
                                               select t;
     SyntaxNode newRoot = node.ReplaceTrivia(commentTrivia, (t1, t2) => default(SyntaxTrivia));
     return newRoot;
 }
开发者ID:joymon,项目名称:joyful-visualstudio,代码行数:8,代码来源:VBCommentedCodeRemover.cs

示例3: RemoveComment

        private Task<Document> RemoveComment(Document document, SyntaxNode root, SyntaxTrivia comment, CancellationToken cancellationToken)
        {
            var line = comment.Token.LeadingTrivia.SplitLines().First(n => n.Contains(comment));

            var newRoot = root.ReplaceTrivia(line, (_, __) => default(SyntaxTrivia));

            var newDocument = document.WithSyntaxRoot(newRoot);

            return Task.FromResult(newDocument);
        }
开发者ID:miya2000,项目名称:CommentAnalyzer,代码行数:10,代码来源:CommentAnalyzerCodeFixProvider.cs

示例4: GetTransformedDocumentAsync

        private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, SyntaxTrivia trivia)
        {
            string text = trivia.ToFullString();
            if (!text.StartsWith("//"))
            {
                return Task.FromResult(document);
            }

            string correctedText = "// " + text.Substring(2).TrimStart(' ');
            SyntaxTrivia corrected = SyntaxFactory.Comment(correctedText).WithoutFormatting();
            Document updatedDocument = document.WithSyntaxRoot(root.ReplaceTrivia(trivia, corrected));

            return Task.FromResult(updatedDocument);
        }
开发者ID:nukefusion,项目名称:StyleCopAnalyzers,代码行数:14,代码来源:SA1005CodeFixProvider.cs

示例5: ProcessTriviaList

        private static SyntaxNode ProcessTriviaList(SyntaxNode syntaxRoot, SyntaxTriviaList triviaList, SyntaxTrivia singleLineComment)
        {
            var index = triviaList.IndexOf(singleLineComment);
            if (index == -1)
            {
                return null;
            }

            index--;
            while (index >= 0)
            {
                switch (triviaList[index].Kind())
                {
                case SyntaxKind.WhitespaceTrivia:
                    index--;
                    break;

                default:
                    return syntaxRoot.ReplaceTrivia(triviaList[index], new[] { triviaList[index], SyntaxFactory.CarriageReturnLineFeed });
                }
            }

            return syntaxRoot.ReplaceTrivia(triviaList[0], new[] { SyntaxFactory.CarriageReturnLineFeed, triviaList[0] });
        }
开发者ID:hickford,项目名称:StyleCopAnalyzers,代码行数:24,代码来源:SA1515CodeFixProvider.cs

示例6: ProcessTriviaList

        private static SyntaxNode ProcessTriviaList(SyntaxNode syntaxRoot, SyntaxTriviaList triviaList, SyntaxTrivia singleLineComment)
        {
            var index = triviaList.IndexOf(singleLineComment);
            if (index == -1)
            {
                return null;
            }

            do
            {
                index++;
            }
            while (!triviaList[index].IsKind(SyntaxKind.EndOfLineTrivia));

            var startOfBlankLine = index;

            do
            {
                index++;
            }
            while (!triviaList[index].IsKind(SyntaxKind.EndOfLineTrivia));

            return syntaxRoot.ReplaceTrivia(triviaList.Skip(startOfBlankLine).Take(index - startOfBlankLine), (t1, t2) => default(SyntaxTrivia));
        }
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:24,代码来源:SA1512CodeFixProvider.cs

示例7: RemoveComments

        private Task<Document> RemoveComments(Document document, SyntaxNode root, SyntaxTrivia comment, CancellationToken cancellationToken)
        {
            var startCommentText = comment.ToFullString().Substring(2).Trim(); // skip "//"
            var endCommentText = Regex.Replace(startCommentText, @"\bstart\b", "end", RegexOptions.IgnoreCase);
            var endCommentRegex = new Regex(string.Join(@"\s+", Regex.Split(endCommentText, @"\s+").Select(n => Regex.Escape(n))), RegexOptions.IgnoreCase);

            var lines = new List<SyntaxTrivia>();

            var node = comment.Token.Parent.AncestorsAndSelf()
                .Where(n => n is BlockSyntax || n is BaseTypeDeclarationSyntax)
                .First();
            var tokens = node.ChildNodesAndTokens();

            foreach (var line in tokens.Where(t => t.HasLeadingTrivia).SelectMany(t => t.GetLeadingTrivia().SplitLines()).SkipWhile(n => !n.Contains(comment)))
            {
                //skip outside of declaration.
                if (line[0].SpanStart < node.SpanStart || line[0].SpanStart > node.Span.End) continue;

                // find line contains SingleLineComment only.
                foreach (var firstTrivia in line.SkipWhile(n => n.Kind() == SyntaxKind.WhitespaceTrivia).Take(1))
                {
                    if (firstTrivia.Kind() == SyntaxKind.SingleLineCommentTrivia)
                    {
                        lines.AddRange(line);

                        var commentText = firstTrivia.ToFullString();

                        if (endCommentRegex.IsMatch(commentText))
                        {
                            goto EOL;
                        }
                    }
                }
            }

        EOL:

            var newRoot = root.ReplaceTrivia(lines, (_, __) => default(SyntaxTrivia));

            var newDocument = document.WithSyntaxRoot(newRoot);

            return Task.FromResult(newDocument);
        }
开发者ID:miya2000,项目名称:CommentAnalyzer,代码行数:43,代码来源:CommentAnalyzerCodeFixProvider.cs


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