Esempio n. 1
0
        private static Expression ConcatenateAndOrExpressions(
            IEnumerable <Filter> filters,
            ParameterExpression itemParameter,
            Type filterableClassType)
        {
            Expression where = null;
            MemberExpression property;
            Expression       filterExpression;

            if (filters != null)
            {
                foreach (var filter in filters)
                {
                    property = RecursivelyPropertyInfoGetter.CreatePropertyExpression(itemParameter, filter.PropertyName);

                    filter.Value = ValueParser.ParseValueToPropertyType(property, filter.Value);

                    filterExpression = CompareExpressionByOperator(
                        filter.Operator,
                        property,
                        Expression.Constant(filter.Value));

                    if (filter.OrFilters != null && filter.OrFilters.Count > 0)
                    {
                        Expression filtersExpressions = ConcatenateAndOrExpressions(filter.OrFilters, itemParameter, filterableClassType);
                        if (filtersExpressions != null)
                        {
                            filterExpression = Expression.OrElse(filterExpression, filtersExpressions);
                        }
                    }

                    if (where != null)
                    {
                        where = Expression.AndAlso(where, filterExpression);
                    }
                    else
                    {
                        where = filterExpression;
                    }
                }
            }

            return(where);
        }