本文整理汇总了C#中System.Linq.Expressions.Expression.GetLambda方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.GetLambda方法的具体用法?C# Expression.GetLambda怎么用?C# Expression.GetLambda使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.GetLambda方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitSelect
Expression VisitSelect(Expression source, Expression selectExpression)
{
var lambda = selectExpression.GetLambda();
if (lambda.Parameters.Count != 1)
throw new NotSupportedException("Select method with T parameter is supported, additional parameters like index are not");
var selectBody = lambda.Body;
if (selectBody is MemberExpression)
RebindPropertiesAndElasticFields(selectBody);
if (selectBody is NewExpression)
RebindSelectBody(selectBody, ((NewExpression)selectBody).Arguments, lambda.Parameters);
if (selectBody is MethodCallExpression)
RebindSelectBody(selectBody, ((MethodCallExpression)selectBody).Arguments, lambda.Parameters);
finalItemType = selectBody.Type;
return Visit(source);
}
示例2: VisitWhere
Expression VisitWhere(Expression source, Expression lambdaPredicate)
{
var lambda = lambdaPredicate.GetLambda();
var criteriaExpression = lambda.Body as CriteriaExpression ?? BooleanMemberAccessBecomesEquals(lambda.Body) as CriteriaExpression;
if (criteriaExpression == null)
throw new NotSupportedException(string.Format("Where expression '{0}' could not be translated", lambda.Body));
searchRequest.Filter = AndCriteria.Combine(searchRequest.Filter, criteriaExpression.Criteria);
return Visit(source);
}
示例3: VisitOrderBy
Expression VisitOrderBy(Expression source, Expression orderByExpression, bool ascending)
{
var lambda = orderByExpression.GetLambda();
var final = Visit(lambda.Body) as MemberExpression;
if (final != null)
{
var fieldName = Mapping.GetFieldName(SourceType, final);
var ignoreUnmapped = final.Type.IsNullable(); // Consider a config switch?
searchRequest.SortOptions.Insert(0, new SortOption(fieldName, ascending, ignoreUnmapped));
}
return Visit(source);
}
示例4: VisitQuery
Expression VisitQuery(Expression source, Expression predicate)
{
var lambda = predicate.GetLambda();
var wasWithin = within;
within = CriteriaWithin.Query;
var body = BooleanMemberAccessBecomesEquals(lambda.Body);
var criteriaExpression = body as CriteriaExpression;
if (criteriaExpression == null)
throw new NotSupportedException(string.Format("Query expression '{0}' could not be translated", body));
searchRequest.Query = AndCriteria.Combine(searchRequest.Query, criteriaExpression.Criteria);
within = wasWithin;
return Visit(source);
}