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


C# ExpressionSyntax.DescendentNodesAndSelf方法代码示例

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


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

示例1: RewritePostfixUnarys

        protected ExpressionSyntax RewritePostfixUnarys(ExpressionSyntax node)
        {
            var expressions = node.DescendentNodesAndSelf().OfType<PostfixUnaryExpressionSyntax>().ToArray();
            if (expressions.Length == 0)
                return node;

            List<string> names = new List<string> (expressions.Length);
            foreach (var expr in expressions)
            {
                if (expr.Kind != SyntaxKind.PostIncrementExpression && expr.Kind != SyntaxKind.PostDecrementExpression)
                    continue; // These aren't the droids we're looking for.

                IdentifierNameSyntax name = FindIdentifierName (expr);
                if (name == null)
                    continue; // We didn't find a name

                if (names.Contains (name.PlainName))
                {
                    var newExpr = GetLogExpression (name.PlainName, expr);
                    node = node.ReplaceNode (expr, newExpr);
                }
                else
                    names.Add (name.PlainName);
            }

            // We'll use a string builder construct our expression.
            StringBuilder builder = new StringBuilder ("LogPostfixValues ((");
            builder.Append (node.ToString());
            builder.Append ("), ");

            bool found = false;
            foreach (string name in names)
            {
                if (found)
                    builder.Append (", ");

                // We need to specify our generic types so we match
                // the params argument type
                builder.Append ("new Tuple<string, object> (\"");
                builder.Append (name);
                builder.Append ("\", ");
                builder.Append (name);
                builder.Append (")");
                found = true;
            }

            if (!found)
                return node; // We didn't find any usable expressions

            builder.Append (")");

            // Parse and return our new expression.
            return Syntax.ParseExpression (builder.ToString());
        }
开发者ID:Mstrymt,项目名称:Instant,代码行数:54,代码来源:LoggingRewriter.cs


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