[8049] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11170] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8049] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Linq.Expressions;
|
---|
| 26 | using HeuristicLab.Services.OKB.DataAccess;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Services.OKB.Query.Filters {
|
---|
| 29 | public class AndFilter : IFilter {
|
---|
| 30 | public List<IFilter> Filters { get; private set; }
|
---|
| 31 |
|
---|
| 32 | public Expression<Func<Run, bool>> Expression {
|
---|
| 33 | get {
|
---|
| 34 | ParameterExpression parameter = System.Linq.Expressions.Expression.Parameter(typeof(Run));
|
---|
| 35 | Expression expr = System.Linq.Expressions.Expression.Constant(true);
|
---|
| 36 | foreach (IFilter filter in Filters)
|
---|
| 37 | expr = System.Linq.Expressions.Expression.AndAlso(expr, System.Linq.Expressions.Expression.Invoke(filter.Expression, parameter));
|
---|
| 38 | return System.Linq.Expressions.Expression.Lambda<Func<Run, bool>>(expr, parameter);
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public AndFilter(IEnumerable<IFilter> filters) {
|
---|
| 43 | Filters = new List<IFilter>(filters);
|
---|
| 44 | }
|
---|
| 45 | public AndFilter(DataTransfer.CombinedFilter filter) {
|
---|
| 46 | Filters = new List<IFilter>(filter.Filters.Select(x => (IFilter)Activator.CreateInstance(Type.GetType(x.FilterTypeName), x)));
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | }
|
---|