本文整理汇总了C#中System.Linq.Expressions.Expression.All方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.All方法的具体用法?C# Expression.All怎么用?C# Expression.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.All方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SquaredDistanceExpression
/// <summary>
/// Creates a new dot product expression.
/// </summary>
/// <param name="components">The ordered components of the two vectors in the order of first vectors coordinates then second vectors coordinates (ex: x0,y0,x1,y1).</param>
/// <param name="reductionExpressionGenerator">The optional expression generator that can be used to produce reduced expressions.</param>
public SquaredDistanceExpression(Expression[] components, IExpressionGenerator reductionExpressionGenerator = null)
: base(reductionExpressionGenerator) {
if (null == components) throw new ArgumentNullException("components");
if (components.Length == 0) throw new ArgumentException("Must have at least 1 component.", "components");
if (components.Length % 2 != 0) throw new ArgumentException("Must have an even number of components.", "components");
Contract.Requires(components.All(x => null != x));
Components = components; // TODO: clone?
if (Components.ContainsNull())
throw new ArgumentException("All components expressions must be non null.", "components");
}
示例2: BindToCall
public static Expression BindToCall(Expression instance, MethodBase method, Expression ctx, OverloadBinder.ArgumentsBinder args)
{
Debug.Assert(method is MethodInfo || method is ConstructorInfo);
var ps = method.GetParameters();
var boundargs = new Expression[ps.Length];
int argi = 0;
for (int i = 0; i < ps.Length; i++)
{
var p = ps[i];
if (argi == 0 && p.IsImplicitParameter())
{
if (p.IsContextParameter())
boundargs[i] = ctx;
else
throw new NotImplementedException();
}
else
{
if (i == ps.Length - 1 && p.IsParamsParameter())
{
var element_type = p.ParameterType.GetElementType();
boundargs[i] = args.BindParams(argi, element_type);
break;
}
else
{
boundargs[i] = args.BindArgument(argi, p);
}
//
argi++;
}
}
//
Debug.Assert(boundargs.All(x => x != null));
//
if (method.IsStatic)
{
instance = null;
}
//
if (method.IsConstructor)
{
return Expression.New((ConstructorInfo)method, boundargs);
}
if (instance != null && method.IsVirtual)
{
// Ugly hack here,
// we NEED to call the method nonvirtually, but LambdaCompiler emits .callvirt always and there is no way how to change it (except we can emit all the stuff by ourselfs).
// We use DynamicMethod to emit .call inside, and use its MethodInfo which is static.
// LambdaCompiler generates .call to static DynamicMethod which calls our method via .call as well,
// after all the inlining, there should be no overhead.
method = WrapInstanceMethodToStatic((MethodInfo)method);
//
var newargs = new Expression[boundargs.Length + 1];
newargs[0] = instance;
Array.Copy(boundargs, 0, newargs, 1, boundargs.Length);
boundargs = newargs;
instance = null;
}
//
return Expression.Call(instance, (MethodInfo)method, boundargs);
}