本文整理汇总了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);
}
示例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));
}
示例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;
}
示例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);
}