|
1 | 1 | using System.Collections; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.Runtime.Serialization; |
3 | 4 | using System.Text.Json; |
4 | 5 | using System.Text.Json.Serialization; |
5 | 6 |
|
6 | 7 | namespace {{ spec.title | caseUcfirst }} |
7 | 8 | { |
| 9 | + public enum Condition |
| 10 | + { |
| 11 | + [EnumMember(Value = "equal")] |
| 12 | + Equal, |
| 13 | + [EnumMember(Value = "notEqual")] |
| 14 | + NotEqual, |
| 15 | + [EnumMember(Value = "greaterThan")] |
| 16 | + GreaterThan, |
| 17 | + [EnumMember(Value = "greaterThanEqual")] |
| 18 | + GreaterThanEqual, |
| 19 | + [EnumMember(Value = "lessThan")] |
| 20 | + LessThan, |
| 21 | + [EnumMember(Value = "lessThanEqual")] |
| 22 | + LessThanEqual, |
| 23 | + [EnumMember(Value = "contains")] |
| 24 | + Contains |
| 25 | + } |
| 26 | + |
| 27 | + public static class ConditionExtensions |
| 28 | + { |
| 29 | + public static string ToValue(this Condition condition) |
| 30 | + { |
| 31 | + return condition switch |
| 32 | + { |
| 33 | + Condition.Equal => "equal", |
| 34 | + Condition.NotEqual => "notEqual", |
| 35 | + Condition.GreaterThan => "greaterThan", |
| 36 | + Condition.GreaterThanEqual => "greaterThanEqual", |
| 37 | + Condition.LessThan => "lessThan", |
| 38 | + Condition.LessThanEqual => "lessThanEqual", |
| 39 | + Condition.Contains => "contains", |
| 40 | + _ => throw new ArgumentOutOfRangeException(nameof(condition), condition, null) |
| 41 | + }; |
| 42 | + } |
| 43 | + } |
| 44 | + |
8 | 45 | public class Operator |
9 | 46 | { |
10 | 47 | [JsonPropertyName("method")] |
@@ -130,9 +167,14 @@ namespace {{ spec.title | caseUcfirst }} |
130 | 167 | return new Operator("arrayDiff", values).ToString(); |
131 | 168 | } |
132 | 169 |
|
133 | | - public static string ArrayFilter(string condition, object? value = null) |
| 170 | + public static string ArrayFilter(Condition condition, object? value = null) |
134 | 171 | { |
135 | | - return new Operator("arrayFilter", new List<object> { condition, value! }).ToString(); |
| 172 | + var values = new List<object> { condition.ToValue() }; |
| 173 | + if (value != null) |
| 174 | + { |
| 175 | + values.Add(value); |
| 176 | + } |
| 177 | + return new Operator("arrayFilter", values).ToString(); |
136 | 178 | } |
137 | 179 |
|
138 | 180 | public static string Concat(object value) |
|
0 commit comments