-
Notifications
You must be signed in to change notification settings - Fork 56
Description
So currently creating just one filter takes 8 lines of code. It is not that much, but making a compound filter with both "and" and "or" condtions takes up to 40 lines, which I would like to optimize.
Currently initialization of a filter class looks like this:
var filter = new PeopleFilter { Property = "Assignee", People = new PeopleFilter.Condition { IsNotEmpty = true } };
And I would like it to look something like this:
var filter = new PeopleFilter("Assignee", PeopleFilter.ConditionType.IsNotEmpty, true);
For this I can add ConditionType enums to filter classes and choose which property to assign in [Filter].Condition initialization automatically. So I expect it to look something like this:
public class PeopleFilter : SinglePropertyFilter { public Condition People { get; set; } public PeopleFilter(string property, PeopleFilter.ConditionType conditionType, object value) { var condition = new Condition(); switch (conditionType) { case ConditionType.Contains: condition.Contains = (string)value; break; case ConditionType.DoesNotContain: condition.DoesNotContain = (string)value; break; case ConditionType.IsEmpty: condition.IsEmpty = (bool)value; break; case ConditionType.IsNotEmpty: condition.IsEmpty = (bool)value; break; default: break; } Property = property; People = condition; } public class Condition { // ... } public enum ConditionType { Contains, DoesNotContain, IsEmpty, IsNotEmpty, } }
Of course there are possible issues with typing value wrongfully. I also thought about making constructors overloads for each possible value type, but that would require creating separate enums for each type.
Please, let me know your thoughts on this idea.