本文整理汇总了C#中SyntaxListBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxListBuilder.Add方法的具体用法?C# SyntaxListBuilder.Add怎么用?C# SyntaxListBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxListBuilder
的用法示例。
在下文中一共展示了SyntaxListBuilder.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToTriviaList
public static SyntaxNode ConvertToTriviaList(this SyntaxNode[] nodes)
{
var builder = new SyntaxListBuilder(nodes.Length);
for (int i = 0; i < nodes.Length; i++)
{
var node = nodes[i];
var nd = node.GetDiagnostics();
foreach (var token in node.GetTokens())
{
builder.Add(token.GetLeadingTrivia());
if (token.Width > 0)
{
var tk = token.WithLeadingTrivia(null).WithTrailingTrivia(null);
System.Diagnostics.Debug.Assert(tk.HasDiagnostics == token.HasDiagnostics);
if (nd != null && nd.Length > 0)
{
if (token != node)
{
tk = tk.WithAdditionalDiagnostics(nd);
}
nd = null;
}
builder.Add(Syntax.SkippedTokens(tk));
}
builder.Add(token.GetTrailingTrivia());
}
}
return builder.ToListNode();
}
示例2: ParseEndOfDirective
private SyntaxToken ParseEndOfDirective(bool ignoreErrors, bool afterPragma = false, bool afterLineNumber = false, bool afterReference = false)
{
var skippedTokens = new SyntaxListBuilder<SyntaxToken>();
// Consume all extranous tokens as leading SkippedTokens trivia.
if (this.CurrentToken.Kind != SyntaxKind.EndOfDirectiveToken &&
this.CurrentToken.Kind != SyntaxKind.EndOfFileToken)
{
skippedTokens = new SyntaxListBuilder<SyntaxToken>(10);
if (!ignoreErrors)
{
ErrorCode errorCode = ErrorCode.ERR_EndOfPPLineExpected;
if (afterPragma)
{
errorCode = ErrorCode.WRN_EndOfPPLineExpected;
}
else if (afterLineNumber)
{
errorCode = ErrorCode.ERR_MissingPPFile;
}
else if (afterReference)
{
errorCode = ErrorCode.ERR_ExpectedPPFile;
}
skippedTokens.Add(this.AddError(this.EatToken().WithoutDiagnosticsGreen(), errorCode));
}
while (this.CurrentToken.Kind != SyntaxKind.EndOfDirectiveToken &&
this.CurrentToken.Kind != SyntaxKind.EndOfFileToken)
{
skippedTokens.Add(this.EatToken().WithoutDiagnosticsGreen());
}
}
// attach text from extraneous tokens as trivia to EndOfDirective token
SyntaxToken endOfDirective = this.CurrentToken.Kind == SyntaxKind.EndOfDirectiveToken
? this.EatToken()
: SyntaxFactory.Token(SyntaxKind.EndOfDirectiveToken);
if (!skippedTokens.IsNull)
{
endOfDirective = endOfDirective.WithLeadingTrivia(SyntaxFactory.SkippedTokensTrivia(skippedTokens.ToList()));
}
return endOfDirective;
}