Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Proposal: filter constructors for cleaner initialization #21

Closed
Labels
enhancementNew feature or request
@asevos

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /