本文整理汇总了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]);
}
示例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);
}
示例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);
}