本文整理汇总了C#中VariableDeclaratorSyntax.GetAllPrecedingTriviaToPreviousToken方法的典型用法代码示例。如果您正苦于以下问题:C# VariableDeclaratorSyntax.GetAllPrecedingTriviaToPreviousToken方法的具体用法?C# VariableDeclaratorSyntax.GetAllPrecedingTriviaToPreviousToken怎么用?C# VariableDeclaratorSyntax.GetAllPrecedingTriviaToPreviousToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VariableDeclaratorSyntax
的用法示例。
在下文中一共展示了VariableDeclaratorSyntax.GetAllPrecedingTriviaToPreviousToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDeclarationExpression
private static DeclarationExpressionSyntax GetDeclarationExpression(
SourceText sourceText, IdentifierNameSyntax identifier,
TypeSyntax newType, VariableDeclaratorSyntax declaratorOpt)
{
newType = newType.WithoutTrivia().WithAdditionalAnnotations(Formatter.Annotation);
var designation = SyntaxFactory.SingleVariableDesignation(identifier.Identifier);
if (declaratorOpt != null)
{
// We're removing a single declarator. Copy any comments it has to the out-var.
//
// Note: this is tricky due to comment ownership. We want hte comments that logically
// belong to the declarator, even if our syntax model attaches them to other tokens.
var precedingTrivia = declaratorOpt.GetAllPrecedingTriviaToPreviousToken(
sourceText, includePreviousTokenTrailingTriviaOnlyIfOnSameLine: true);
if (precedingTrivia.Any(t => t.IsSingleOrMultiLineComment()))
{
designation = designation.WithPrependedLeadingTrivia(MassageTrivia(precedingTrivia));
}
if (declaratorOpt.GetTrailingTrivia().Any(t => t.IsSingleOrMultiLineComment()))
{
designation = designation.WithAppendedTrailingTrivia(MassageTrivia(declaratorOpt.GetTrailingTrivia()));
}
}
return SyntaxFactory.DeclarationExpression(newType, designation);
}