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


C# BinaryExpression.ChangeLeftRight方法代码示例

本文整理汇总了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);
		}
开发者ID:crazle,项目名称:Shaolinq,代码行数:51,代码来源:ProjectionAsyncRewriter.cs


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