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


C# SyntaxNode.GetTrailingTrivia方法代码示例

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


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

示例1: ReplaceDateTimeAsync

        private async Task<Document> ReplaceDateTimeAsync(Document document, 
                         SyntaxNode node,
                         CancellationToken cancellationToken)
        {
            // Get the root syntax node for the current document
            var root = await document.GetSyntaxRootAsync();

            // Convert the syntax node into the specialized kind
            var convertedNode = (IdentifierNameSyntax)node;

            // Create a new syntax node
            var newNode = convertedNode?.WithIdentifier(SyntaxFactory.
                          ParseToken("DateTimeOffset")).
                          WithLeadingTrivia(node.GetLeadingTrivia()).
                          WithTrailingTrivia(node.GetTrailingTrivia());

            // Create a new root syntax node for the current document
            // replacing the syntax node that has diagnostic with
            // a new syntax node
            var newRoot = root.ReplaceNode(node, newNode);

            // Generate a new document
            var newDocument = document.WithSyntaxRoot(newRoot);
            return newDocument;
        }
开发者ID:AlessandroDelSole,项目名称:RoslynSuccinctly,代码行数:25,代码来源:CodeFixProvider.cs

示例2: GetBestNewLineTrivia

        /// <summary>
        /// Look at the context of the node to determine the best possible new line trivia.  It will prefer 
        /// existing new lines over creating a new one to help ensure the same new lines are preserved 
        /// throughout the file. 
        /// </summary>
        internal static SyntaxTrivia GetBestNewLineTrivia(SyntaxNode node, SyntaxTrivia? defaultNewLineTrivia = null)
        {
            SyntaxTrivia trivia;
            if (TryGetExistingNewLine(node.GetLeadingTrivia(), out trivia) ||
                TryGetExistingNewLine(node.GetTrailingTrivia(), out trivia))
            {
                return trivia;
            }

            return defaultNewLineTrivia ?? SyntaxFactory.CarriageReturnLineFeed;
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:16,代码来源:SyntaxUtil.cs

示例3: ReplaceAddExpressionByStringBuilderAppendExpression

 private static SyntaxNode ReplaceAddExpressionByStringBuilderAppendExpression(AssignmentExpressionSyntax assignmentExpression, SyntaxNode expressionStatement, SyntaxNode expressionStatementParent, string builderName)
 {
     var appendExpressionOnLoop = assignmentExpression.IsKind(SyntaxKind.SimpleAssignmentExpression)
         ? SyntaxFactory.ParseStatement($"{builderName}.Append({((BinaryExpressionSyntax)assignmentExpression.Right).Right.ToString()});\r\n")
         : SyntaxFactory.ParseStatement($"{builderName}.Append({assignmentExpression.Right.ToString()});\r\n");
     appendExpressionOnLoop = appendExpressionOnLoop
         .WithLeadingTrivia(expressionStatement.GetLeadingTrivia())
         .WithTrailingTrivia(expressionStatement.GetTrailingTrivia());
     var newExpressionStatementParent = expressionStatementParent.ReplaceNode(expressionStatement, appendExpressionOnLoop);
     return newExpressionStatementParent;
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:11,代码来源:StringBuilderInLoopCodeFixProvider.cs

示例4: UseVarAsync

        private Task<Solution> UseVarAsync(Document document, SyntaxNode root, SyntaxNode statement)
        {
            var varIdentifier = SyntaxFactory.IdentifierName("var")
                                             .WithLeadingTrivia(statement.GetLeadingTrivia())
                                             .WithTrailingTrivia(statement.GetTrailingTrivia());

            var newRoot = root.ReplaceNode(statement, varIdentifier);

            var newDocument = document.WithSyntaxRoot(newRoot);
            return Task.FromResult(newDocument.Project.Solution);
        }
开发者ID:nemec,项目名称:VSDiagnostics,代码行数:11,代码来源:TypeToVarCodeFix.cs

示例5: GetFix

        private async Task<Document> GetFix(Document document, SyntaxNode expression, CancellationToken cancellationToken)
        {
            // Rewrite the expression to include a .ConfigureAwait() after it. We reattach trailing trivia to the end.
            // This is especially important for VB, as the end-of-line may be in the trivia
            DocumentEditor editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false);
            SyntaxGenerator generator = editor.Generator;
            SyntaxNode memberAccess = generator.MemberAccessExpression(expression.WithoutTrailingTrivia(), "ConfigureAwait");
            SyntaxNode falseLiteral = generator.FalseLiteralExpression();
            SyntaxNode invocation = generator.InvocationExpression(memberAccess, falseLiteral);
            invocation = invocation.WithLeadingTrivia(expression.GetLeadingTrivia()).WithTrailingTrivia(expression.GetTrailingTrivia());

            editor.ReplaceNode(expression, invocation);
            return editor.GetChangedDocument();
        }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:14,代码来源:DoNotDirectlyAwaitATask.Fixer.cs

示例6: ConvertToArrayEmpty

        private async Task<Document> ConvertToArrayEmpty(Document document, SyntaxNode nodeToFix, CancellationToken cancellationToken)
        {
            DocumentEditor editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false);

            SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
            SyntaxGenerator generator = editor.Generator;

            SyntaxNode variableDecl = generator.GetDeclaration(nodeToFix, DeclarationKind.Variable);
            SyntaxNode typeNode = generator.GetType(variableDecl);

            var type = semanticModel.GetTypeInfo(typeNode, cancellationToken).Type as IArrayTypeSymbol;
            INamedTypeSymbol arrayTypeSymbol = semanticModel.Compilation.GetTypeByMetadataName(AvoidZeroLengthArrayAllocationsAnalyzer.ArrayTypeName);

            SyntaxNode arrayEmptyName = generator.QualifiedName(generator.TypeExpression(arrayTypeSymbol),
                                                         generator.GenericName(AvoidZeroLengthArrayAllocationsAnalyzer.ArrayEmptyMethodName, type.ElementType));
            SyntaxNode arrayEmptyInvocation = generator.InvocationExpression(arrayEmptyName);
            arrayEmptyInvocation = arrayEmptyInvocation.WithLeadingTrivia(nodeToFix.GetLeadingTrivia()).WithTrailingTrivia(nodeToFix.GetTrailingTrivia());
            editor.ReplaceNode(nodeToFix, arrayEmptyInvocation);
            return editor.GetChangedDocument();
        }
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:20,代码来源:AvoidZeroLengthArrayAllocations.Fixer.cs

示例7: CreateEqualsExpression

        internal SyntaxNode CreateEqualsExpression(SyntaxGenerator syntaxFactoryService, SemanticModel model, SyntaxNode operand1, SyntaxNode operand2, bool isEquals)
        {
            var stringType = model.Compilation.GetSpecialType(SpecialType.System_String);
            var memberAccess = syntaxFactoryService.MemberAccessExpression(
                        syntaxFactoryService.TypeExpression(stringType),
                        syntaxFactoryService.IdentifierName(UseOrdinalStringComparisonAnalyzer.EqualsMethodName));
            var ordinal = CreateOrdinalMemberAccess(syntaxFactoryService, model);
            var invocation = syntaxFactoryService.InvocationExpression(
                memberAccess,
                operand1,
                operand2.WithoutTrailingTrivia(),
                ordinal)
                .WithAdditionalAnnotations(Formatter.Annotation);
            if (!isEquals)
            {
                invocation = syntaxFactoryService.LogicalNotExpression(invocation);
            }

            invocation = invocation.WithTrailingTrivia(operand2.GetTrailingTrivia());

            return invocation;
        }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:22,代码来源:UseOrdinalStringComparison.Fixer.cs

示例8: WriteTrailingTrivia

 public static void WriteTrailingTrivia(OutputWriter writer, SyntaxNode node)
 {
     SyntaxTriviaList triviaList = node.GetTrailingTrivia();
     foreach (var trivia in triviaList)
     {
         if (trivia.CSharpKind() == SyntaxKind.SingleLineCommentTrivia ||
             trivia.CSharpKind() == SyntaxKind.MultiLineCommentTrivia ||
             trivia.CSharpKind() == SyntaxKind.SingleLineDocumentationCommentTrivia ||
             trivia.CSharpKind() == SyntaxKind.MultiLineDocumentationCommentTrivia ||
             trivia.CSharpKind() == SyntaxKind.WhitespaceTrivia)
         {
             if (trivia.CSharpKind() == SyntaxKind.WhitespaceTrivia)
             {
                 if (trivia.ToFullString().EndsWith("\n"))
                 {
                     writer.WriteLine();
                     writer.WriteIndent();
                 }
             }
             else
                 writer.WriteLine(trivia.ToFullString());
         }
     }
 }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:24,代码来源:TriviaProcessor.cs

示例9: HasLineEnding

 internal static bool HasLineEnding(SyntaxNode node)
 {
     return node.HasTrailingTrivia &&
         node.GetTrailingTrivia().Last().IsKind(SyntaxKind.EndOfLineTrivia);
 }
开发者ID:jakobehn,项目名称:sonarlint-vs,代码行数:5,代码来源:RedundantInheritanceListCodeFixProvider.cs

示例10: HasWatchComment

		bool HasWatchComment(SyntaxNode node)
		{
			// expect that only valid node types are passed here
			return
				node
					.GetTrailingTrivia()
					.Any(t => t.Kind() == SyntaxKind.SingleLineCommentTrivia && t.ToString().StartsWith("//="));
		}
开发者ID:praeclarum,项目名称:Continuous,代码行数:8,代码来源:ContinuousEnv.MonoDevelop.cs

示例11: Visit

            public override SyntaxNode Visit(SyntaxNode node)
            {
                PatternSearchResult result;
                if (!_results.TryGetValue(node, out result))
                    return base.Visit(node);

                var pattern = _patterns[result.Search];
                var rewrittenCaptures = result.Captures.Select(VisitCapture)
                                                       .ToDictionary(c => c.Variable);

                var expander = new PatternExpander(pattern, rewrittenCaptures);
                var syntaxNode = expander.Visit(pattern.Node);
                return syntaxNode.WithLeadingTrivia(node.GetLeadingTrivia())
                                 .WithTrailingTrivia(node.GetTrailingTrivia());
            }
开发者ID:terrajobst,项目名称:apiporter,代码行数:15,代码来源:PatternReplacement.RunAsync.cs


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