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


C# BlockSyntax.ChildNodes方法代码示例

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


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

示例1: Block

        private static string Block(BlockSyntax node, bool braces = true)
        {
            var output = (braces ? "{" + NewLine : "");

            output += string.Join("", node.ChildNodes().Select(SyntaxNode));

            return output + (braces ? "}" + NewLine + NewLine : "");
        }
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:8,代码来源:SyntaxNodeConverter.cs

示例2: VisitBlock

            public override void VisitBlock(BlockSyntax node)
            {
                var statements = node.ChildNodes().OfType<ExpressionStatementSyntax>();
                var invocations = statements.Select(s => s.Expression).OfType<InvocationExpressionSyntax>();
                var glOperators = invocations.Select(i => i.Expression).OfType<MemberAccessExpressionSyntax>()
                    .Where(m => m.IsKind(SyntaxKind.SimpleMemberAccessExpression)).Where(s => s.GetFirstToken().Text == nameof(GL));
                var beginEnds = glOperators.Select(g => Tuple.Create(g.Parent as InvocationExpressionSyntax, g.ChildNodes().Skip(1).FirstOrDefault()?.GetFirstToken().Text))
                    .Where(p => p.Item2 == nameof(GL.Begin) || p.Item2 == nameof(GL.End));

                // filtering
                if (!beginEnds.Any())
                {
                    base.VisitBlock(node);
                    return;
                }

                // block contains GL.Begin() or GL.End()
                var counter = 0;
                Location prevBeginLocation = null;
                foreach (var pair in beginEnds)
                {
                    if (pair.Item2 == nameof(GL.Begin))
                    {
                        counter++;
                        if (counter > 1)
                        {
                            Diagnostics.Add(Diagnostic.Create(
                                descriptor: Rule,
                                location: prevBeginLocation,
                                messageArgs: nameof(GL) + "." + nameof(GL.End)));
                            counter = 1;
                        }
                        prevBeginLocation = pair.Item1.GetLocation();
                    }
                    else if (pair.Item2 == nameof(GL.End))
                    {
                        counter--;
                        if (counter < 0)
                        {
                            Diagnostics.Add(Diagnostic.Create(
                                descriptor: Rule,
                                location: pair.Item1.GetLocation(),
                                messageArgs: nameof(GL) + "." + nameof(GL.Begin)));
                            counter = 0;
                        }
                    }
                }
                if (counter > 0)
                {
                    Diagnostics.Add(Diagnostic.Create(
                        descriptor: Rule,
                        location: prevBeginLocation,
                        messageArgs: nameof(GL) + "." + nameof(GL.End)));
                }

                base.VisitBlock(node);
            }
开发者ID:occar421,项目名称:OpenTKAnalyzer,代码行数:57,代码来源:BeginEndAnalyzer.cs

示例3: VisitBlock

        public override SyntaxNode VisitBlock(BlockSyntax node)
        {
            var value = base.VisitBlock(node);
            if (_isExpressionTransformer && _transform && node.Parent is MethodDeclarationSyntax)
            {
                _isExpressionTransformer = false;
                _transform = false;
                var newStatements = new[] { string.Concat("value = new ", _expressionTransformerNamespaceDot, _edmxName, @"ExpressionTransformer().TransformExpression(expression, contextName);"), @"
            if (value != expression)
                return value;" };

                var statements = node.ChildNodes().OfType<StatementSyntax>().ToList();
                return node.DefineStatements(statements.Take(statements.Count - 1).Union(newStatements.Select(s => Syntax.ParseStatement(s))).Union(new[] { statements[statements.Count - 1] }));
            }
            return value;
        }
开发者ID:bnjMichel,项目名称:waqs,代码行数:16,代码来源:ExpressionTransformerRewriter.cs

示例4: GetLocalNames

 // doesn't include variables declared in declaration expressions
 private static void GetLocalNames(BlockSyntax block, ref List<SyntaxToken> result)
 {
     foreach (var child in block.ChildNodes())
     {
         if (child.IsKind(SyntaxKind.LocalDeclarationStatement))
         {
             GetLocalNames(((LocalDeclarationStatementSyntax)child).Declaration, ref result);
         }
     }
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:11,代码来源:StatementSyntaxComparer.cs

示例5: VisitBlock

            public override void VisitBlock(BlockSyntax node)
            {
                var statements = node.ChildNodes().OfType<ExpressionStatementSyntax>();
                var invocations = statements.Select(s => s.Expression).OfType<InvocationExpressionSyntax>();
                var glOperators = invocations.Select(i => i.Expression).OfType<MemberAccessExpressionSyntax>()
                    .Where(m => m.IsKind(SyntaxKind.SimpleMemberAccessExpression)).Where(s => s.GetFirstToken().Text == nameof(GL));
                var pushPops = glOperators.Select(g => Tuple.Create(g.Parent as InvocationExpressionSyntax, g.ChildNodes().Skip(1).First().GetFirstToken().Text))
                    .Where(p => p.Item2.StartsWith("Push") || p.Item2.StartsWith("Pop"));

                // filtering
                if (!pushPops.Any())
                {
                    base.VisitBlock(node);
                    return;
                }

                // block contains GL.Push???() or GL.Pop???
                var counters = new int[reverseRouter.Count]; // new int[5]
                var prevPushLocations = new Location[reverseRouter.Count]; // new Location[5]
                foreach (var pair in pushPops)
                {
                    var route = router[pair.Item2];
                    if (pair.Item2.StartsWith("Push"))
                    {
                        counters[route]++;
                        if (counters[route] > 1)
                        {
                            Diagnostics.Add(Diagnostic.Create(
                                descriptor: Rule,
                                location: prevPushLocations[route],
                                messageArgs: nameof(GL) + ".Pop" + reverseRouter[route]));
                            counters[router[pair.Item2]] = 1;
                        }
                        prevPushLocations[route] = pair.Item1.GetLocation();
                    }
                    else if (pair.Item2.StartsWith("Pop"))
                    {
                        counters[route]--;
                        if (counters[route] < 0)
                        {
                            Diagnostics.Add(Diagnostic.Create(
                                descriptor: Rule,
                                location: pair.Item1.GetLocation(),
                                messageArgs: nameof(GL) + ".Push" + reverseRouter[route]));
                            counters[route] = 0;
                        }
                    }
                }
                for (int i = 0; i < counters.Length; i++)
                {
                    if (counters[i] > 0)
                    {
                        Diagnostics.Add(Diagnostic.Create(
                            descriptor: Rule,
                            location: prevPushLocations[i],
                            messageArgs: nameof(GL) + ".Pop" + reverseRouter[i]));
                    }
                }

                base.VisitBlock(node);
            }
开发者ID:occar421,项目名称:OpenTKAnalyzer,代码行数:61,代码来源:PushPopAnalyzer.cs

示例6: VisitBlock

        public void VisitBlock(BlockSyntax node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.Validate();

            WriteLeadingTrivia(node);

            bool writeNewlineBefore = !(
                node.Parent is BlockSyntax ||
                node.Parent is LabeledStatementSyntax
            );

            if (!node.ChildNodes().Any())
            {
                _writer.EmptyBlock(writeNewlineBefore);
            }
            else
            {
                _writer.BeginBlock(writeNewlineBefore, true);

                _writer.PushBraceFormatting(_writer.Configuration.BracesLayout.Other);

                foreach (var statement in node.Statements)
                {
                    statement.Accept(this);
                }

                _writer.PopBraceFormatting();

                _writer.EndBlock();
            }

            WriteTrailingTrivia(node);
        }
开发者ID:modulexcite,项目名称:CSharpSyntax,代码行数:36,代码来源:SyntaxPrinter.cs


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