當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。