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


C# SyntaxToken.GetLeadingTrivia方法代码示例

本文整理汇总了C#中SyntaxToken.GetLeadingTrivia方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.GetLeadingTrivia方法的具体用法?C# SyntaxToken.GetLeadingTrivia怎么用?C# SyntaxToken.GetLeadingTrivia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxToken的用法示例。


在下文中一共展示了SyntaxToken.GetLeadingTrivia方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddToken

        // Process a token. and add to the list of triva/tokens we're accumulating.
        public void AddToken(SyntaxToken token, bool isFirst, bool isLast)
        {
            bool isMissing = token.IsMissing;
            if (token.HasLeadingTrivia && (isFirst || isMissing || token.GetLeadingTrivia().TriviaListContainsStructuredTrivia()))
            {
                FinishInProgressTokens();
                AddTrivia(token.GetLeadingTrivia());
                token = ((SyntaxToken)token.WithLeadingTrivia(null));
            }

            ////if (!preserveExistingDiagnostics)
            ////{
            ////    token = token.WithoutDiagnostics();
            ////}

            SyntaxNode trailingTrivia = null;
            if (token.HasTrailingTrivia && (isLast || isMissing || token.GetTrailingTrivia().TriviaListContainsStructuredTrivia()))
            {
                trailingTrivia = token.GetTrailingTrivia();
                token = ((SyntaxToken)token.WithTrailingTrivia(null));
            }

            if (isMissing)
            {
                // Don't add missing tokens to skipped tokens, but preserve their diagnostics.
                ////if (token.ContainsDiagnostics())
                ////{
                ////    // Move diagnostics on missing token to next token.
                ////    if (diagnosticsToAdd != null)
                ////    {
                ////        diagnosticsToAdd = diagnosticsToAdd.Concat(token.GetDiagnostics());
                ////    }
                ////    else
                ////    {
                ////        diagnosticsToAdd = token.GetDiagnostics();
                ////    }

                ////    addDiagnosticsToFirstTokenOnly = true;
                ////}
            }
            else
            {
                skippedTokensBuilder.Add(token);
            }

            if (trailingTrivia != null)
            {
                FinishInProgressTokens();
                AddTrivia(trailingTrivia);
            }

            if (isFirst && addDiagnosticsToFirstTokenOnly)
            {
                FinishInProgressTokens(); // implicitly adds the diagnostics.
            }
        }
开发者ID:akrisiun,项目名称:Microsoft.Language.Xml,代码行数:57,代码来源:SkippedTriviaBuilder.cs

示例2: TruncateIdentifier

        // Ignore everything after the 128th character by setting the value text of the token
        // from the prefix.  This is for backwards compatibility with Dev 10.
        private static SyntaxToken TruncateIdentifier(SyntaxToken identifier)
        {
            if (identifier.Width > MAX_DIRECTIVE_IDENTIFIER_WIDTH)
            {
                var leading = identifier.GetLeadingTrivia();
                var trailing = identifier.GetTrailingTrivia();

                string text = identifier.ToString();
                string identifierPart = text.Substring(0, MAX_DIRECTIVE_IDENTIFIER_WIDTH);

                identifier = SyntaxFactory.Identifier(SyntaxKind.IdentifierToken, leading, text, identifierPart, trailing);
            }
            return identifier;
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:16,代码来源:DirectiveParser.cs

示例3: PushToken

            private void PushToken(SyntaxToken token)
            {
                var trailing = token.GetTrailingTrivia();
                if (trailing != null)
                {
                    this.Push(trailing);
                }

                this.Push(token);
                var leading = token.GetLeadingTrivia();
                if (leading != null)
                {
                    this.Push(leading);
                }
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:15,代码来源:SyntaxDiagnosticInfoList.cs


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