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


C# SyntaxToken.FullWidth方法代码示例

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


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

示例1: Between

            public static AnalysisResult Between(SyntaxToken token1, SyntaxToken token2)
            {
                if (!token1.HasTrailingTrivia && !token2.HasLeadingTrivia)
                {
                    return default(AnalysisResult);
                }

                var result = default(AnalysisResult);

                if (token1.IsMissing && token1.FullWidth() == 0)
                {
                    // Consider the following case:
                    //
                    //          return // <- note the missing semicolon
                    //      }
                    //
                    // in this case, the compiler will insert a missing semicolon token at the 
                    // start of the line containing the close curly.  This is problematic as it
                    // means that if we're looking at the token-pair for the semicolon and close-
                    // curly, then we'll think there is no newline here.  Because we think there
                    // is no newline, we won't attempt to indent in a manner that preserves tabs
                    // (if the user has 'use tabs for indent' enabled).
                    //
                    // Here we detect if our previous token is an empty missing token.  If so,
                    // we look back to the previous non-missing token to see if it ends with a
                    // newline.  If so, we keep track of that so we'll appropriately indent later
                    // on. 

                    var previousNonMissingToken = token1.GetPreviousToken(includeZeroWidth: false, includeSkipped: true);
                    if (previousNonMissingToken.TrailingTrivia.Count > 0 &&
                        previousNonMissingToken.TrailingTrivia.Last().Kind() == SyntaxKind.EndOfLineTrivia)
                    {
                        result.LineBreaks = 1;
                    }
                }
                else
                {
                    Analyze(token1.TrailingTrivia, ref result);
                }

                Analyze(token2.LeadingTrivia, ref result);

                return result;
            }
开发者ID:noahfalk,项目名称:roslyn,代码行数:44,代码来源:TriviaDataFactory.Analyzer.cs

示例2: Between

            public static AnalysisResult Between(SyntaxToken token1, SyntaxToken token2)
            {
                if (!token1.HasTrailingTrivia && !token2.HasLeadingTrivia)
                {
                    return default(AnalysisResult);
                }

                var result = default(AnalysisResult);

                if (token1.IsMissing && token1.FullWidth() == 0)
                {
                    // Consider the following case:
                    //
                    //          return // <- note the missing semicolon
                    //      }
                    //
                    // in this case, the compiler will insert a missing semicolon token at the 
                    // start of the line containing the close curly.  This is problematic as it
                    // means that if we're looking at the token-pair for the semicolon and close-
                    // curly, then we'll think there is no newline here.  Because we think there
                    // is no newline, we won't attempt to indent in a manner that preserves tabs
                    // (if the user has 'use tabs for indent' enabled).
                    //
                    // Here we detect if our previous token is an empty missing token.  If so,
                    // we look back to the previous non-missing token to see if it ends with a
                    // newline.  If so, we keep track of that so we'll appropriately indent later
                    // on. 

                    // Keep walking backward until we hit a token whose *full width* is greater than
                    // 0.  See if this token has an end of line trivia at the end of it.  Note:
                    // we need to "includeZeroWidth" tokens because we can have zero width tokens
                    // that still have a full width that is non-zero.  i.e. a missing token that
                    // still has trailing trivia on it.

                    for (var currentToken = token1; !currentToken.IsKind(SyntaxKind.None);)
                    {
                        var previousToken = currentToken.GetPreviousToken(includeSkipped: false, includeZeroWidth: true);
                        if (previousToken.FullWidth() == 0)
                        {
                            currentToken = previousToken;
                            continue;
                        }

                        // Finally hit the first previous token with non-zero full width.
                        if (previousToken.TrailingTrivia.Count > 0 &&
                            previousToken.TrailingTrivia.Last().Kind() == SyntaxKind.EndOfLineTrivia)
                        {
                            result.LineBreaks = 1;
                        }

                        break;
                    }
                }
                else
                {
                    Analyze(token1.TrailingTrivia, ref result);
                }

                Analyze(token2.LeadingTrivia, ref result);

                return result;
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:62,代码来源:TriviaDataFactory.Analyzer.cs


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