Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Services.OKB/3.3/Query/Filters/OrFilter.cs @ 15584

Last change on this file since 15584 was 15584, checked in by swagner, 6 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 2.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Linq.Expressions;
26using HeuristicLab.Services.OKB.DataAccess;
27
28namespace HeuristicLab.Services.OKB.Query.Filters {
29  public class OrFilter : 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(false);
36        foreach (IFilter filter in Filters)
37          expr = System.Linq.Expressions.Expression.OrElse(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 OrFilter(IEnumerable<IFilter> filters) {
43      Filters = new List<IFilter>(filters);
44    }
45    public OrFilter(DataTransfer.CombinedFilter filter) {
46      Filters = new List<IFilter>(filter.Filters.Select(x => (IFilter)Activator.CreateInstance(Type.GetType(x.FilterTypeName), x)));
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.