-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Filter.cs
91 lines (81 loc) · 2.73 KB
/
Filter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
namespace RentmanSharp
{
public class Filter
{
public readonly FilterProperty[] FilterProperties;
public readonly Pagination Pagination;
public static Filter IncrementFilter = new IncrementFilter();
public Filter(in Pagination? pagination = null, params FilterProperty[] filterProperties)
{
this.FilterProperties = filterProperties;
this.Pagination = pagination ?? new Pagination(300, 0);
}
public Filter Next()
{
return new Filter(this.Pagination.Next(),FilterProperties);
}
public override string ToString()
{
string s = Pagination.ToString();
foreach (var filterProperty in this.FilterProperties)
{
s += "&";
s += filterProperty.ToString();
}
return s;
}
public readonly struct FilterProperty
{
public readonly string Name;
public readonly string Value;
public readonly EFilterOperator Operator;
public FilterProperty(string name, string value, EFilterOperator @operator)
{
this.Name = name;
this.Value = value;
this.Operator = @operator;
}
public override string ToString()
{
return $"{this.Name}{operatorString(this.Operator)}={this.Value}";
}
private static string operatorString(EFilterOperator @operator)
{
switch (@operator)
{
case EFilterOperator.Equals:
return string.Empty;
case EFilterOperator.LessThan:
return "[lt]";
case EFilterOperator.GreaterTan:
return "[gt]";
case EFilterOperator.LessThanOrEqualsTo:
return "[lte]";
case EFilterOperator.GreaterThanOrEqualsTo:
return "[gte]";
case EFilterOperator.NotEqualTo:
return "[neq]";
case EFilterOperator.IsNull:
return "[isnull]";
}
throw new NotImplementedException();
}
public enum EFilterOperator
{
Equals,
LessThan,
GreaterTan,
LessThanOrEqualsTo,
GreaterThanOrEqualsTo,
NotEqualTo,
IsNull
}
}
}
internal sealed class IncrementFilter: Filter
{
internal IncrementFilter()
{
}
}
}