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


C# ConditionalExpression.Update方法代码示例

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


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

示例1: VisitConditional

        protected override Expression VisitConditional(ConditionalExpression node)
        {
            var children = new[] {node.Test, node.IfTrue, node.IfFalse};

            VisitChildren(children);

            return node.Update(children[0], children[1], children[2]);
        }
开发者ID:RossMerr,项目名称:CouchbaseNetClient,代码行数:8,代码来源:LambdaSimplifyingExpressionVisitor.cs

示例2: VisitConditional

        protected override Expression VisitConditional(ConditionalExpression node)
        {
            Debug.WriteLine(node);
            var ifTrue = Visit(node.IfTrue);
            var ifFalse = Visit(node.IfFalse);
            var test = Visit(node.Test);

            Expression expression;
            if (ExtractNullableArgument(test, ifTrue, out expression))
            {
                return Expression.Coalesce(expression, ifFalse);
            }
            var ifTrueBinary = UnwrapConvertExpression(ifTrue) as BinaryExpression;
            if (ifTrueBinary != null)
            {
                BinaryExpression result;
                if (TryConvert1(test, ifTrueBinary, out result))
                    return result;
            }
            
            var binaryExpression = test as BinaryExpression;
            var ifTrueConstant = ifTrue as ConstantExpression;
            var ifFalseConstant = ifFalse as ConstantExpression;

            if (binaryExpression != null)
            {
                BinaryExpression result;
                if (ifTrueBinary != null && TryConvert2(binaryExpression, ifTrueBinary, out result))
                {
                    return result;
                }
                if (TryConvert(ifTrueConstant, binaryExpression, ifFalse, out result, false))
                {
                    return result;
                }
                if (TryConvert(ifFalseConstant, binaryExpression, ifTrue, out result, true))
                {
                    return result;
                }
                if (binaryExpression.NodeType == ExpressionType.NotEqual)
                {
                    if (binaryExpression.Left == node.IfTrue)
                    {
                        if (binaryExpression.Right is DefaultExpression)
                        {
                            return Expression.Coalesce(binaryExpression.Left, ifFalse);
                        }
                        var rightConstant = binaryExpression.Right as ConstantExpression;
                        if (rightConstant != null && rightConstant.Value == null)
                        {
                            return Expression.Coalesce(binaryExpression.Left, ifFalse);
                        }
                    }
                }
            }

            if (test.NodeType == ExpressionType.Not)
            {
                if (ifTrueConstant != null)
                {
                    if (ifTrueConstant.Value as bool? == false)
                    {
                        return Expression.AndAlso(((UnaryExpression) test).Operand, ifFalse);
                    }
                }
            }

            return node.Update(test, ifTrue, ifFalse);
        }
开发者ID:bensho,项目名称:DelegateDecompiler,代码行数:69,代码来源:OptimizeExpressionVisitor.cs

示例3: replaceConditionalNodeChild

 private ConditionalExpression replaceConditionalNodeChild(ConditionalExpression conditionalExpression, Expression oldChild, Expression newChild)
 {
     Expression test = conditionalExpression.Test.Equals(oldChild) ? newChild : conditionalExpression.Test;
     Expression ifTrue = conditionalExpression.IfTrue.Equals(oldChild) ? newChild : conditionalExpression.IfTrue;
     Expression ifFalse = conditionalExpression.IfFalse.Equals(oldChild) ? newChild : conditionalExpression.IfFalse;
     return conditionalExpression.Update(test, ifTrue, ifFalse);
 }
开发者ID:radamus,项目名称:OptimizableLINQ,代码行数:7,代码来源:TreeNodeReplacer.cs


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