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


C# Expression.GetLambda方法代码示例

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

示例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);
        }
开发者ID:jarlrasm,项目名称:ElasticLINQ,代码行数:13,代码来源:ElasticQueryTranslator.cs

示例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);
        }
开发者ID:jarlrasm,项目名称:ElasticLINQ,代码行数:13,代码来源:ElasticQueryTranslator.cs

示例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);
        }
开发者ID:jarlrasm,项目名称:ElasticLINQ,代码行数:16,代码来源:ElasticQueryTranslator.cs


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