-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (44 loc) · 1.88 KB
/
Program.cs
File metadata and controls
49 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace ReflectionDynamicFilter
{
using Enumerations;
using Helpers;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var listEmployees = GetListEmployees();
//Filter direct by method
var listFilters1 = new List<FilterModel>()
{
new FilterModel("Salary.Type.Description", "Type1", RelationalOperatorsEnum.Equal),
new FilterModel("Salary.Value", 1000, RelationalOperatorsEnum.Equal),
new FilterModel("Name", "Mendes", RelationalOperatorsEnum.Contains, LogicalOperatorsEnum.Or),
};
var resultFilter1 = listEmployees.Filter(listFilters1);
//Generate predicate
Func<EmployeeModel, bool> newPredicate = FilterHelper.GeneratePredicate<EmployeeModel>(listFilters1);
var resultFilter2 = listEmployees.Where(newPredicate);
var listFilters2 = new List<FilterModel>()
{
new FilterModel("Name", "tte", RelationalOperatorsEnum.Contains),
new FilterModel("Age", 30, RelationalOperatorsEnum.Equal),
new FilterModel("Salary.Value", 2000, RelationalOperatorsEnum.GreaterThan)
};
var resultFilter3 = listEmployees.Filter(listFilters2);
}
static List<EmployeeModel> GetListEmployees()
{
return new List<EmployeeModel>
{
new EmployeeModel(1, "David", "Software Developer", 50,1000,"Type1"),
new EmployeeModel(2, "Charlotte", "Finance", 30, 5000,"Type1"),
new EmployeeModel(3, "Elizabeth", "Marketing", 40, 3000,"Type1"),
new EmployeeModel(4, "Thomas", "Office Administration", 35, 4000,"Type1")
};
}
}
}