本文整理汇总了C#中SyntaxTriviaList.Last方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTriviaList.Last方法的具体用法?C# SyntaxTriviaList.Last怎么用?C# SyntaxTriviaList.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxTriviaList
的用法示例。
在下文中一共展示了SyntaxTriviaList.Last方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveNewLinesFromBottom
/// <summary>
/// Remove all extra new lines from the begining of a close brace token. This is only called in
/// the case at least one new line is present hence we don't have to worry about the single line
/// case.
/// </summary>
private static SyntaxTriviaList RemoveNewLinesFromBottom(SyntaxTriviaList triviaList)
{
var index = triviaList.Count - 1;
var searching = true;
while (index >= 0 && searching)
{
var current = triviaList[index];
switch (current.Kind())
{
case SyntaxKind.WhitespaceTrivia:
case SyntaxKind.EndOfLineTrivia:
index--;
break;
default:
searching = false;
break;
}
}
// Nothing to adjust, the removal of new lines from the top of the list will handle all of the
// important cases.
if (index < 0)
{
return triviaList;
}
var list = new List<SyntaxTrivia>(triviaList.Count);
for (int i = 0; i <= index; i++)
{
list.Add(triviaList[i]);
}
// A directive has an implicit new line after it.
if (!list[index].IsDirective)
{
list.Add(SyntaxUtil.GetBestNewLineTrivia(triviaList));
}
if (triviaList.Last().IsKind(SyntaxKind.WhitespaceTrivia))
{
list.Add(triviaList.Last());
}
return SyntaxFactory.TriviaList(list);
}