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


C# SyntaxNode.ChildTokens方法代码示例

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


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

示例1: IsSingleCharViolation

 private bool IsSingleCharViolation(SyntaxNode declaration)
 {
     var identifier = declaration.ChildTokens().First(t => t.RawKind == IdentifierToken);
     if (IsInLoop(declaration)) return false;
     if (IsInLamda(declaration)) return false;
     return identifier.Value.ToString().Length == 1;
 }
开发者ID:birksimon,项目名称:CodeAnalysis,代码行数:7,代码来源:NameInspector.cs

示例2: GetDiagnosticLocation

        private static Location GetDiagnosticLocation(SyntaxNode node)
        {
            if (node.HasLeadingTrivia)
            {
                return node.GetLeadingTrivia()[0].GetLocation();
            }

            var firstToken = node.ChildTokens().FirstOrDefault();
            if (firstToken != default(SyntaxToken))
            {
                return node.ChildTokens().First().GetLocation();
            }

            return Location.None;
        }
开发者ID:nukefusion,项目名称:StyleCopAnalyzers,代码行数:15,代码来源:SA1516ElementsMustBeSeparatedByBlankLine.cs

示例3: DetermineContentPosition

        /// <summary>
        /// Determines the content's block position depending on the node type.
        /// </summary>
        /// <param name="node">The node to extract the content position from.</param>
        /// <returns>The determined content position or 0 if not found.</returns>
        private int DetermineContentPosition(SyntaxNode node)
        {
            if(node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            // Select the content node element depending on the node type
            TextSpan? contentTextSpan = null;
            switch (node.Kind())
            {
                // Accessor list content
                case SyntaxKind.PropertyDeclaration:
                case SyntaxKind.IndexerDeclaration:
                case SyntaxKind.EventDeclaration:
                    AccessorListSyntax accessorList = node.DescendantNodes().OfType<AccessorListSyntax>().FirstOrDefault();
                    if (null != accessorList)
                    {
                        contentTextSpan = accessorList.FullSpan;
                    }
                    break;

                // Contains children
                case SyntaxKind.NamespaceDeclaration:
                case SyntaxKind.InterfaceDeclaration:
                case SyntaxKind.ClassDeclaration:
                    SyntaxToken token = node.ChildTokens().FirstOrDefault(x => x.Kind() == SyntaxKind.OpenBraceToken);
                    if (null != token)
                    {
                        contentTextSpan = token.FullSpan;
                    }
                    break;

                // Block content
                case SyntaxKind.ConstructorDeclaration:
                case SyntaxKind.DestructorDeclaration:
                case SyntaxKind.MethodDeclaration:
                case SyntaxKind.GetAccessorDeclaration:
                case SyntaxKind.SetAccessorDeclaration:
                case SyntaxKind.AddAccessorDeclaration:
                case SyntaxKind.RemoveAccessorDeclaration:
                    BlockSyntax block = node.DescendantNodes().OfType<BlockSyntax>().FirstOrDefault();
                    if (null != block)
                    {
                        contentTextSpan = block.FullSpan;
                    }
                    break;

                // Not processed by projbook csharp extractor
                default:
                    break;
            }

            // Compute a line break insensitive position based on the fetched content text span if any is found
            if (null != contentTextSpan)
            {
                int relativeTextSpanStart = contentTextSpan.Value.Start - node.FullSpan.Start;
                return node
                    .ToFullString()
                    .Substring(0, relativeTextSpanStart)
                    .Replace("\r\n", "")
                    .Replace("\n", "").Length;
            }

            // Otherwise return 0 as default value
            return 0;
        }
开发者ID:FransBouma,项目名称:DocNet,代码行数:71,代码来源:CSharpSnippetExtractor.cs

示例4: IsNumberSeriesViolation

 // TODO: Exception e is allowed                    
 private bool IsNumberSeriesViolation(SyntaxNode declaration)
 {
     const string numberSeriesRegex = "^[a-zA-Z][0-9]{1,3}$";
     var identifier = declaration.ChildTokens().First(t => t.RawKind == IdentifierToken);
     return Regex.IsMatch(identifier.Value.ToString(), numberSeriesRegex);
 }
开发者ID:birksimon,项目名称:CodeAnalysis,代码行数:7,代码来源:NameInspector.cs


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