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


C# SyntaxNode.DescendantTokens方法代码示例

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


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

示例1: PrintAllTokens

 /// <summary>
 /// Print all the tokens.
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 private string PrintAllTokens(SyntaxNode node)
 {
     var tokens = node.DescendantTokens();
     var sb = new StringBuilder();
     foreach (var token in tokens)
     {
         sb.AppendLine(token.Kind.ToString()+ " " + token.GetText());
     }
     return sb.ToString();
 }
开发者ID:nkcsgexi,项目名称:GhostFactor2,代码行数:15,代码来源:CommentsAnalyzerTests.cs

示例2: AreEquivalentIgnoringLambdaBodies

        /// <summary>
        /// Compares content of two nodes ignoring lambda bodies and trivia.
        /// </summary>
        public static bool AreEquivalentIgnoringLambdaBodies(SyntaxNode oldNode, SyntaxNode newNode)
        {
            // all tokens that don't belong to a lambda body:
            var oldTokens = oldNode.DescendantTokens(node => node == oldNode || !IsLambdaBodyStatementOrExpression(node));
            var newTokens = newNode.DescendantTokens(node => node == newNode || !IsLambdaBodyStatementOrExpression(node));

            return oldTokens.SequenceEqual(newTokens, SyntaxFactory.AreEquivalent);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:11,代码来源:LambdaUtilities.cs

示例3: GetIdentifierOrGlobalNamespaceTokensWithText

        private static ImmutableArray<SyntaxToken> GetIdentifierOrGlobalNamespaceTokensWithText(
            ISyntaxFactsService syntaxFacts, Document document, VersionStamp version, SyntaxNode root, SourceText sourceText,
            string text, CancellationToken cancellationToken)
        {
            Func<SyntaxToken, bool> candidate = t =>
                syntaxFacts.IsGlobalNamespaceKeyword(t) || (syntaxFacts.IsIdentifier(t) && syntaxFacts.TextMatch(t.ValueText, text));

            // identifier is not escaped
            if (sourceText != null)
            {
                return GetTokensFromText(syntaxFacts, document, version, root, sourceText, text, candidate, cancellationToken);
            }

            // identifier is escaped
            return root.DescendantTokens(descendIntoTrivia: true).Where(candidate).ToImmutableArray();
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:16,代码来源:FindReferenceCache.cs

示例4: GetFlattenedNodeText

        private string GetFlattenedNodeText(SyntaxNode node)
        {
            const int cutoff = 30;

            var lastEnd = node.Span.Start;
            var sb = new StringBuilder();
            foreach (var token in node.DescendantTokens(descendIntoTrivia: false))
            {
                if (token.Span.Start - lastEnd > 0)
                {
                    sb.Append(" ");
                }

                sb.Append(token.ToString());
                lastEnd = token.Span.End;

                if (sb.Length > cutoff)
                {
                    break;
                }
            }

            return sb.ToString() + (sb.Length > cutoff ? " ..." : string.Empty);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:24,代码来源:AnalysisContextInfo.cs


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