Hi I have to apply filter on generic class. The sample class is as follows
public class Sample<T>
{
List<T> sourceList = new List<T>();
public void applyFilter(string propertyName , EnumOperator operator , object value)
{
}
}
Here I want to implement filter using linq or dynamic linq but am not getting any positive direction to implement this functionality.
Please give me some positive direction so that I can implement this functionality.
Thanks.
I would recommend returning an filtered list instead of modifying the source, and also the string “operator” is a C# keyword, so the signature of the method could be:
where I assume that the
EnumOperatoris anenumwith values like this:and that you have some way to check if for an operator a value passes or fails the test, something along the lines of:
Given that, you can do something like:
That said, you can always use LINQ’s methods to filter almost anything without resorting to reflection.