Modifying the Filter Pattern with Generic Lambda Expressions





Pipeline & Filter ( ), , , - ( ) . , WPF- . .





Pipeline & Filter

. , (generic) -. . ​​ :





ConditionAggregator



- , Condition<T>



. Filter<T>



ConditionAggregator



Condition<T>



(condition) . apply () Filter<T>



, check () ICondition<T>



. ConditionAggregator<T>



OnFilterChanged



. , . Filter .









MVVM . (View Model) MVVM - . -, . ConditionAggregator<T>



OnFilterChanged



, apply. .





Employee



. Generic



T



Filter



Employee



. EmployeeList



. .





public EmployeeList(IEmployeesRepository repository, ConditionAggregator<employee> conditionAggregator)
        {
            this.repository = repository;
            this.filters = new ConcreteFilter<employee>(conditionAggregator);
            conditionAggregator.OnFilterChanged += this.FilterList;
            _ = initAsync();
        }
      
      







FilterList



OnFilterChanged



, .





private void FilterList()
{
    this.Employees = this.filters.Apply(this.employeesFullList);
}
      
      



EmployeesViewModel



. EmployeeTypeselected



, ConditionAggregator



. - -, .





public EmployeesViewModel(IEmployeesRepository repository)
        {
            this.repository = repository;
            Condition&lt;employee&gt; filterEmployee = new Condition&lt;employee&gt;((e) =&gt; e.employeeCode == this.EmployeeTypeSelected);
            this.conditionAggregator = new ConditionAggregator&lt;employee&gt;(new List&lt;condition&lt;employee&gt;&gt; { filterEmployee });
            this.EmployeeList = new EmployeeList(repository, this.conditionAggregator);            
        }  
&lt;/condition&lt;employee&gt;&lt;/employee&gt;&lt;/employee&gt;&lt;/employee&gt;
      
      







-. , ConditionAggregator



. , , .





WPF.Demo.DataFilter



- WPF. . WPF.Demo.DataFilter.ViewModels



, . WPF.Demo.DataFilter.Common



Pipeline & Filter. WPF.Demo.DataFilter.DAL



json- .





:






" ". "", -, , , . .













All Articles