当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxListBuilder.Add方法代码示例

本文整理汇总了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();
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:33,代码来源:SyntaxNodeArrayExtensions.cs

示例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;
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:48,代码来源:DirectiveParser.cs


注:本文中的SyntaxListBuilder.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。