本文整理汇总了C#中System.Linq.Expressions.MethodCallExpression.GetSelectLambda方法的典型用法代码示例。如果您正苦于以下问题:C# MethodCallExpression.GetSelectLambda方法的具体用法?C# MethodCallExpression.GetSelectLambda怎么用?C# MethodCallExpression.GetSelectLambda使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.GetSelectLambda方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OutputForLoop
protected void OutputForLoop(MethodCallExpression expr)
{
var indexVar = expr.Method.IsSelect (_linqType) ?
expr.GetSelectLambda ().Parameters[0] :
expr.Arguments[2].ExpectLambda ().Parameters[1];
var range = expr.Arguments[0].Expect<MethodCallExpression> (ExpressionType.Call);
var start = Expr (range.Arguments[0]);
if (range.Method.DeclaringType == typeof (Enumerable))
{
var len = Expr (range.Arguments[1]);
CodeOut ("for (int {0} = {1}; {0} < {2}; {0}++)", indexVar, start, len);
}
else
{
var end = Expr (range.Arguments[1]);
var step = Expr (range.Arguments[2]);
CodeOut ("for (int {0} = {1}; {0} != {2}; {0} += {3})", indexVar, start, end, step);
}
CodeOut ("{");
_tabLevel++;
}
示例2: IterateArray
protected void IterateArray(MethodCallExpression expr)
{
var array = expr.Arguments[0];
var member = array.SkipUnary (ExpressionType.Not)
.Expect<MemberExpression> (ExpressionType.MemberAccess).Member;
var len = 0;
var field = member as FieldInfo;
if (field != null)
len = field.ExpectFixedArrayAttribute ().Length;
else if (_constants.ContainsKey (member.Name))
{
var constant = _constants[member.Name];
if (!constant.Type.IsArray)
throw new ParseException ("Invalid array expression. Referenced constant is not an array.");
var nai = constant.Value.Expect<NewArrayExpression> (ExpressionType.NewArrayInit);
len = nai.Expressions.Count;
}
else
throw new ParseException ("Invalid array expression. " +
"Expected uniform field reference or constant array. Encountered: " + array);
var indexVar = NewIndexVar ("ind");
var item = expr.Method.IsSelect (_linqType) ?
expr.GetSelectLambda ().Parameters[0] :
expr.Arguments[2].ExpectLambda ().Parameters[1];
CodeOut ("for (int {0} = 0; {0} < {1}; {0}++)", indexVar, len);
CodeOut ("{");
_tabLevel++;
CodeOut ("{0} {1} = {2}[{3}];", MapType (item.Type), item.Name,
Expr (array), indexVar);
}