本文整理汇总了C#中LiteralExpressionSyntax.GetFirstToken方法的典型用法代码示例。如果您正苦于以下问题:C# LiteralExpressionSyntax.GetFirstToken方法的具体用法?C# LiteralExpressionSyntax.GetFirstToken怎么用?C# LiteralExpressionSyntax.GetFirstToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LiteralExpressionSyntax
的用法示例。
在下文中一共展示了LiteralExpressionSyntax.GetFirstToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatXmlAsync
private async Task<Document> FormatXmlAsync(Document document, LiteralExpressionSyntax sleSyntax, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken);
var tree = root.SyntaxTree;
//Get the character position of the LiteralExpressionSyntax
FileLinePositionSpan position = tree.GetLineSpan(sleSyntax.Span);
int cSpace = position.StartLinePosition.Character;
//Figure out the preceeding trivia since we can't get the column position from GetLineSpan
var parentTrivia = sleSyntax.GetLeadingTrivia().ToFullString();
var xml = sleSyntax.GetFirstToken().ValueText;
var newXmlText = FormatXml(xml);
//Process each line of the formatted XML and prepend the parent trivia & spaces
string[] xmlLines = newXmlText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
for (int i = 1; i < xmlLines.Length; i++)
{
xmlLines[i] = parentTrivia + new String(' ', (cSpace + 2)) + xmlLines[i];
}
newXmlText = String.Join("\r\n", xmlLines);
var newXmlValue = "@\"" + newXmlText + "\"";
var newNode = SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression,
SyntaxFactory.Token(SyntaxTriviaList.Empty, SyntaxKind.StringLiteralToken, newXmlValue, newXmlText, SyntaxTriviaList.Empty));
var newRoot = root.ReplaceNode(sleSyntax, newNode);
return document.WithSyntaxRoot(newRoot);
}