本文整理汇总了C#中System.Linq.Expressions.BinaryExpression.ChangeLeftRight方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpression.ChangeLeftRight方法的具体用法?C# BinaryExpression.ChangeLeftRight怎么用?C# BinaryExpression.ChangeLeftRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.BinaryExpression
的用法示例。
在下文中一共展示了BinaryExpression.ChangeLeftRight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitBinary
protected override Expression VisitBinary(BinaryExpression binaryExpression)
{
var left = this.Visit(binaryExpression.Left);
var right = this.Visit(binaryExpression.Right);
if (left.Type == binaryExpression.Left.Type && right.Type == binaryExpression.Right.Type)
{
return binaryExpression.ChangeLeftRight(left, right);
}
if (!IsTaskType(left.Type) && !IsTaskType(right.Type))
{
return binaryExpression.ChangeLeftRight(left, right);
}
if (IsTaskType(left.Type) && IsTaskType(right.Type))
{
var leftVar = Expression.Parameter(left.Type);
var rightVar = Expression.Parameter(right.Type);
var variables = new[] { leftVar, rightVar };
var expression = CreateChainedCalls(leftVar, rightVar);
var lambda = Expression.Lambda(binaryExpression.ChangeLeftRight(Expression.Property(leftVar, "Result"), Expression.Property(rightVar, "Result")), Expression.Parameter(expression.Type));
return Expression.Block(variables, Expression.Assign(leftVar, left), Expression.Assign(rightVar, right), Expression.Call(expression, "ContinueWith", new[] { lambda.ReturnType }, lambda));
}
if (this.IsTaskType(left.Type))
{
var leftVar = Expression.Parameter(left.Type);
var variables = new[] { leftVar };
var expression = CreateChainedCalls(leftVar);
var lambda = Expression.Lambda(binaryExpression.ChangeLeftRight(Expression.Property(leftVar, "Result"), right), Expression.Parameter(expression.Type));
return Expression.Block(variables, Expression.Assign(leftVar, left), Expression.Call(expression, "ContinueWith", new[] { lambda.ReturnType }, lambda));
}
if (this.IsTaskType(right.Type))
{
var rightVar = Expression.Parameter(right.Type);
var variables = new[] { rightVar };
var expression = CreateChainedCalls(rightVar);
var lambda = Expression.Lambda(binaryExpression.ChangeLeftRight(left, Expression.Property(rightVar, "Result")), Expression.Parameter(expression.Type));
return Expression.Block(variables, Expression.Assign(rightVar, right), Expression.Call(expression, "ContinueWith", new[] { lambda.ReturnType }, lambda));
}
return base.VisitBinary(binaryExpression);
}