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


C# SyntaxNode.GetTrailingTrivia方法代码示例

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


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

示例1: HandleDeclarationAsync

        private async Task<Document> HandleDeclarationAsync(Document document, SyntaxNode root, SyntaxNode node, CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
            var declarationContext = node.Parent;

            TypeSyntax typeSyntax = null;
            if (declarationContext is VariableDeclarationSyntax)
            {
                typeSyntax = ((VariableDeclarationSyntax)declarationContext).Type;
            }
            else if (declarationContext is ForEachStatementSyntax)
            {
                typeSyntax = ((ForEachStatementSyntax)declarationContext).Type;
            }
            else
            {
                Contract.Fail($"unhandled kind {declarationContext.Kind().ToString()}");
            }

            var typeSymbol = semanticModel.GetTypeInfo(typeSyntax).ConvertedType;

            var typeName = typeSymbol.GenerateTypeSyntax()
                                     .WithLeadingTrivia(node.GetLeadingTrivia())
                                     .WithTrailingTrivia(node.GetTrailingTrivia());

            Debug.Assert(!typeName.ContainsDiagnostics, "Explicit type replacement likely introduced an error in code");

            var newRoot = root.ReplaceNode(node, typeName);
            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:30,代码来源:UseExplicitTypeCodeFixProvider.cs

示例2: ReplaceTypeWithVarAsync

        private static Task<Document> ReplaceTypeWithVarAsync(Document document, SyntaxNode root, SyntaxNode node)
        {
            var implicitType = SyntaxFactory.IdentifierName("var")
                                            .WithLeadingTrivia(node.GetLeadingTrivia())
                                            .WithTrailingTrivia(node.GetTrailingTrivia());

            var newRoot = root.ReplaceNode(node, implicitType);
            return Task.FromResult(document.WithSyntaxRoot(newRoot));
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:9,代码来源:UseImplicitTypeCodeFixProvider.cs

示例3: 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(CA1309DiagnosticAnalyzer.EqualsMethodName));
            var ordinal = CreateOrdinalMemberAccess(syntaxFactoryService, model);
            var invocation = syntaxFactoryService.InvocationExpression(
                memberAccess,
                operand1,
                operand2.WithTrailingTrivia(),
                ordinal)
                .WithAdditionalAnnotations(Formatter.Annotation);
            if (!isEquals)
            {
                invocation = syntaxFactoryService.LogicalNotExpression(invocation);
            }

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

            return invocation;
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:22,代码来源:CA1309CodeFixProviderBase.cs

示例4: GetUpdatedDocumentAsync

        internal override Task<Document> GetUpdatedDocumentAsync(
            Document document, SemanticModel model, SyntaxNode root,
            SyntaxNode nodeToFix, string diagnosticId, CancellationToken cancellationToken)
        {
            ArrayTypeSyntax arrayType = GetArrayType(nodeToFix);
            if (arrayType != null)
            {
                TypeSyntax elementType = arrayType.ElementType.WithoutLeadingTrivia().WithoutTrailingTrivia();
                if (arrayType.RankSpecifiers.Count > 1)
                {
                    elementType = SyntaxFactory.ArrayType(elementType, SyntaxFactory.List(arrayType.RankSpecifiers.Skip(1)));
                }

                InvocationExpressionSyntax syntax = InvokeStaticGenericParameterlessMethod(
                    model.Compilation.GetTypeByMetadataName("System.Array"),
                    EmptyArrayDiagnosticAnalyzer.ArrayEmptyMethodName,
                    elementType.WithoutLeadingTrivia().WithoutTrailingTrivia());

                if (nodeToFix.HasLeadingTrivia)
                {
                    syntax = syntax.WithLeadingTrivia(nodeToFix.GetLeadingTrivia());
                }

                if (nodeToFix.HasTrailingTrivia)
                {
                    syntax = syntax.WithTrailingTrivia(nodeToFix.GetTrailingTrivia());
                }

                if (syntax != null)
                {
                    root = root.ReplaceNode(nodeToFix, syntax);
                    document = document.WithSyntaxRoot(root);
                }
            }

            return Task.FromResult(document);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:37,代码来源:CSharpEmptyArrayCodeFixProvider.cs


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