-
Notifications
You must be signed in to change notification settings - Fork 0
Home
FilterCore
is a project that I developed trying to abstract the predicate of LINQ to attributes and classes.
I have used an old and obsolete version of this code for .NET and for the sake of learning, I decided to create a better version for .NET Core and share it via GitHub.
FilterCore
is a static class that exposes some generic extension methods to filter data. Unlike the existing extension methods, those overloads expects a class that implements an FilterCore.Interfaces.IFilter
interface.
To use FilterCore
is simple:
Include the using using FilterCore;
in your class. At your collection of IEnumerable<T>
, or IQueryable<T>
, call the Where
method that accepts a object as parameter.
Create a class that implements FilterCore.Interfaces.IFilter
.
public class FilterClass : IFilter
{
public int CurrentPage { get; set; }
public int PageSize { get; set; }
}
For each property or field of your filter class that you would like to use as a filter, decorate it the FilterCore.Attributes.FilterAttribute
.
[Filter("FullName", FilterOperator.Like)]
public string Name { get; set; }
The FilterCore.Attributes.FilterAttribute
has two required arguments and one optional. The first argument is the name of the property or field from the type of your collection that you will filter. You can chain inner complex object in your using the navigation like in normal code (use ".", EX: [Filter("ChildObject.Value", FilterOperator.GreaterThan)]
).
The second argument is an FilterCore.Enums.FilterOperator
enum. It has all operations availables to use against the property or field of your filter class.
The third argument is optional and it verifies if the value of your filter property or field, when null, shoul be used to compare at the collection.
The following structure is read by FilterCore
this way:
For each object in collection, the property FullName
contains the value of property Name
of filter class.
[Filter("FullName", FilterOperator.Like)]
public string Name { get; set; }
You can use as many as FilterAttribute
as you like on each property or field.