| | 1 | | using Fluorite.Extensions; |
| | 2 | | using Fluorite.Strainer.Models.Filtering.Operators; |
| | 3 | | using System.Collections.ObjectModel; |
| | 4 | | using System.Linq.Expressions; |
| | 5 | | using System.Reflection; |
| | 6 | |
|
| | 7 | | namespace Fluorite.Strainer.Services.Filtering; |
| | 8 | |
|
| | 9 | | public static class FilterOperatorMapper |
| | 10 | | { |
| | 11 | | static FilterOperatorMapper() |
| | 12 | | { |
| 1 | 13 | | DefaultOperators = new ReadOnlyDictionary<string, IFilterOperator>( |
| 1 | 14 | | GetDefaultFilterOperators() |
| 41 | 15 | | .ToDictionary(filterOperator => filterOperator.Symbol, filterOperator => filterOperator)); |
| 1 | 16 | | } |
| | 17 | |
|
| 352 | 18 | | public static IReadOnlyDictionary<string, IFilterOperator> DefaultOperators { get; } |
| | 19 | |
|
| | 20 | | private static IFilterOperator[] GetDefaultFilterOperators() |
| | 21 | | { |
| 1 | 22 | | return GetEqualFilterOperators() |
| 1 | 23 | | .Concat( |
| 1 | 24 | | GetLessThanFilterOperators(), |
| 1 | 25 | | GetGreaterThanFilterOperators(), |
| 1 | 26 | | GetStringFilterOperators(), |
| 1 | 27 | | GetStringNegatedFilterOperators(), |
| 1 | 28 | | GetEqualCaseInsensitiveFilterOperators(), |
| 1 | 29 | | GetStringCaseInsensitiveFilterOperators(), |
| 1 | 30 | | GetStringNegatedCaseInsensitiveFilterOperators()) |
| 1 | 31 | | .ToArray(); |
| | 32 | | } |
| | 33 | |
|
| | 34 | | private static List<IFilterOperator> GetEqualFilterOperators() |
| | 35 | | { |
| 1 | 36 | | return new List<IFilterOperator> |
| 1 | 37 | | { |
| 1 | 38 | | new FilterOperatorBuilder() |
| 1 | 39 | | .HasSymbol(FilterOperatorSymbols.EqualsSymbol) |
| 1 | 40 | | .HasName("equal") |
| 1 | 41 | | .HasExpression((context) => |
| 1 | 42 | | { |
| 20 | 43 | | if (context.IsMaterializedQueryable && context.IsCaseInsensitiveForValues && context.IsStringBasedPr |
| 1 | 44 | | { |
| 10 | 45 | | return Expression.Call( |
| 10 | 46 | | typeof(string).GetMethod( |
| 10 | 47 | | nameof(string.Equals), |
| 10 | 48 | | BindingFlags.Static | BindingFlags.Public, |
| 10 | 49 | | null, |
| 10 | 50 | | new Type[] { typeof(string), typeof(string), typeof(StringComparison) }, |
| 10 | 51 | | null), |
| 10 | 52 | | context.PropertyValue, |
| 10 | 53 | | context.FilterValue, |
| 10 | 54 | | Expression.Constant(StringComparison.OrdinalIgnoreCase)); |
| 1 | 55 | | } |
| 1 | 56 | | else |
| 1 | 57 | | { |
| 10 | 58 | | return Expression.Equal(context.PropertyValue, context.FilterValue); |
| 1 | 59 | | } |
| 1 | 60 | | }) |
| 1 | 61 | | .Build(), |
| 1 | 62 | | new FilterOperatorBuilder() |
| 1 | 63 | | .HasSymbol(FilterOperatorSymbols.DoesNotEqual) |
| 1 | 64 | | .HasName("does not equal") |
| 1 | 65 | | .HasExpression((context) => |
| 1 | 66 | | { |
| 20 | 67 | | if (context.IsMaterializedQueryable && context.IsCaseInsensitiveForValues && context.IsStringBasedPr |
| 1 | 68 | | { |
| 10 | 69 | | return Expression.Not(Expression.Call( |
| 10 | 70 | | typeof(string).GetMethod( |
| 10 | 71 | | nameof(string.Equals), |
| 10 | 72 | | BindingFlags.Static | BindingFlags.Public, |
| 10 | 73 | | null, |
| 10 | 74 | | new Type[] { typeof(string), typeof(string), typeof(StringComparison) }, |
| 10 | 75 | | null), |
| 10 | 76 | | context.PropertyValue, |
| 10 | 77 | | context.FilterValue, |
| 10 | 78 | | Expression.Constant(StringComparison.OrdinalIgnoreCase))); |
| 1 | 79 | | } |
| 1 | 80 | | else |
| 1 | 81 | | { |
| 10 | 82 | | return Expression.NotEqual(context.PropertyValue, context.FilterValue); |
| 1 | 83 | | } |
| 1 | 84 | | }) |
| 1 | 85 | | .Build(), |
| 1 | 86 | | }; |
| | 87 | | } |
| | 88 | |
|
| | 89 | | private static IEnumerable<IFilterOperator> GetLessThanFilterOperators() |
| | 90 | | { |
| 1 | 91 | | return new List<IFilterOperator> |
| 1 | 92 | | { |
| 1 | 93 | | new FilterOperatorBuilder().HasSymbol(FilterOperatorSymbols.LessThan) |
| 1 | 94 | | .HasName("less than") |
| 6 | 95 | | .HasExpression((context) => Expression.LessThan(context.PropertyValue, context.FilterValue)) |
| 1 | 96 | | .Build(), |
| 1 | 97 | | new FilterOperatorBuilder().HasSymbol(FilterOperatorSymbols.LessThanOrEqualTo) |
| 1 | 98 | | .HasName("less than or equal to") |
| 6 | 99 | | .HasExpression((context) => Expression.LessThanOrEqual(context.PropertyValue, context.FilterValue)) |
| 1 | 100 | | .Build(), |
| 1 | 101 | | }; |
| | 102 | | } |
| | 103 | |
|
| | 104 | | private static IEnumerable<IFilterOperator> GetGreaterThanFilterOperators() |
| | 105 | | { |
| 1 | 106 | | return new List<IFilterOperator> |
| 1 | 107 | | { |
| 1 | 108 | | new FilterOperatorBuilder().HasSymbol(FilterOperatorSymbols.GreaterThan) |
| 1 | 109 | | .HasName("greater than") |
| 6 | 110 | | .HasExpression((context) => Expression.GreaterThan(context.PropertyValue, context.FilterValue)) |
| 1 | 111 | | .Build(), |
| 1 | 112 | | new FilterOperatorBuilder().HasSymbol(FilterOperatorSymbols.GreaterThanOrEqualTo) |
| 1 | 113 | | .HasName("greater than or equal to") |
| 6 | 114 | | .HasExpression((context) => Expression.GreaterThanOrEqual(context.PropertyValue, context.FilterValue)) |
| 1 | 115 | | .Build(), |
| 1 | 116 | | }; |
| | 117 | | } |
| | 118 | |
|
| | 119 | | private static IEnumerable<IFilterOperator> GetStringFilterOperators() |
| | 120 | | { |
| 1 | 121 | | return new List<IFilterOperator> |
| 1 | 122 | | { |
| 1 | 123 | | new FilterOperatorBuilder() |
| 1 | 124 | | .HasSymbol(FilterOperatorSymbols.Contains) |
| 1 | 125 | | .HasName("contains") |
| 1 | 126 | | .HasExpression((context) => |
| 1 | 127 | | { |
| 18 | 128 | | if (context.IsMaterializedQueryable && context.IsCaseInsensitiveForValues) |
| 1 | 129 | | { |
| 9 | 130 | | return Expression.Call( |
| 9 | 131 | | context.PropertyValue, |
| 9 | 132 | | typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string), typeof(String |
| 9 | 133 | | context.FilterValue, |
| 9 | 134 | | Expression.Constant(StringComparison.OrdinalIgnoreCase)); |
| 1 | 135 | | } |
| 1 | 136 | | else |
| 1 | 137 | | { |
| 9 | 138 | | return Expression.Call( |
| 9 | 139 | | context.PropertyValue, |
| 9 | 140 | | typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string) }), |
| 9 | 141 | | context.FilterValue); |
| 1 | 142 | | } |
| 1 | 143 | | }) |
| 1 | 144 | | .IsStringBased() |
| 1 | 145 | | .Build(), |
| 1 | 146 | | new FilterOperatorBuilder() |
| 1 | 147 | | .HasSymbol(FilterOperatorSymbols.StartsWith) |
| 1 | 148 | | .HasName("starts with") |
| 1 | 149 | | .HasExpression((context) => |
| 1 | 150 | | { |
| 18 | 151 | | if (context.IsMaterializedQueryable && context.IsCaseInsensitiveForValues) |
| 1 | 152 | | { |
| 9 | 153 | | return Expression.Call( |
| 9 | 154 | | context.PropertyValue, |
| 9 | 155 | | typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string), typeof(Stri |
| 9 | 156 | | context.FilterValue, |
| 9 | 157 | | Expression.Constant(StringComparison.OrdinalIgnoreCase)); |
| 1 | 158 | | } |
| 1 | 159 | | else |
| 1 | 160 | | { |
| 9 | 161 | | return Expression.Call( |
| 9 | 162 | | context.PropertyValue, |
| 9 | 163 | | typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string) }), |
| 9 | 164 | | context.FilterValue); |
| 1 | 165 | | } |
| 1 | 166 | | }) |
| 1 | 167 | | .IsStringBased() |
| 1 | 168 | | .Build(), |
| 1 | 169 | | new FilterOperatorBuilder() |
| 1 | 170 | | .HasSymbol(FilterOperatorSymbols.EndsWith) |
| 1 | 171 | | .HasName("ends with") |
| 1 | 172 | | .HasExpression((context) => |
| 1 | 173 | | { |
| 18 | 174 | | if (context.IsMaterializedQueryable && context.IsCaseInsensitiveForValues) |
| 1 | 175 | | { |
| 9 | 176 | | return Expression.Call( |
| 9 | 177 | | context.PropertyValue, |
| 9 | 178 | | typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string), typeof(String |
| 9 | 179 | | context.FilterValue, |
| 9 | 180 | | Expression.Constant(StringComparison.OrdinalIgnoreCase)); |
| 1 | 181 | | } |
| 1 | 182 | | else |
| 1 | 183 | | { |
| 9 | 184 | | return Expression.Call( |
| 9 | 185 | | context.PropertyValue, |
| 9 | 186 | | typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string) }), |
| 9 | 187 | | context.FilterValue); |
| 1 | 188 | | } |
| 1 | 189 | | }) |
| 1 | 190 | | .IsStringBased() |
| 1 | 191 | | .Build(), |
| 1 | 192 | | }; |
| | 193 | | } |
| | 194 | |
|
| | 195 | | private static IEnumerable<IFilterOperator> GetStringNegatedFilterOperators() |
| | 196 | | { |
| 1 | 197 | | return new List<IFilterOperator> |
| 1 | 198 | | { |
| 1 | 199 | | new FilterOperatorBuilder() |
| 1 | 200 | | .HasSymbol(FilterOperatorSymbols.DoesNotContain) |
| 1 | 201 | | .HasName("does not contain") |
| 1 | 202 | | .HasExpression((context) => |
| 1 | 203 | | { |
| 18 | 204 | | if (context.IsMaterializedQueryable && context.IsCaseInsensitiveForValues) |
| 1 | 205 | | { |
| 9 | 206 | | return Expression.Not(Expression.Call( |
| 9 | 207 | | context.PropertyValue, |
| 9 | 208 | | typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string), typeof(String |
| 9 | 209 | | context.FilterValue, |
| 9 | 210 | | Expression.Constant(StringComparison.OrdinalIgnoreCase))); |
| 1 | 211 | | } |
| 1 | 212 | | else |
| 1 | 213 | | { |
| 9 | 214 | | return Expression.Not(Expression.Call( |
| 9 | 215 | | context.PropertyValue, |
| 9 | 216 | | typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string) }), |
| 9 | 217 | | context.FilterValue)); |
| 1 | 218 | | } |
| 1 | 219 | | }) |
| 1 | 220 | | .IsStringBased() |
| 1 | 221 | | .Build(), |
| 1 | 222 | | new FilterOperatorBuilder() |
| 1 | 223 | | .HasSymbol(FilterOperatorSymbols.DoesNotStartWith) |
| 1 | 224 | | .HasName("does not start with") |
| 1 | 225 | | .HasExpression((context) => |
| 1 | 226 | | { |
| 18 | 227 | | if (context.IsMaterializedQueryable && context.IsCaseInsensitiveForValues) |
| 1 | 228 | | { |
| 9 | 229 | | return Expression.Not(Expression.Call( |
| 9 | 230 | | context.PropertyValue, |
| 9 | 231 | | typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string), typeof(Stri |
| 9 | 232 | | context.FilterValue, |
| 9 | 233 | | Expression.Constant(StringComparison.OrdinalIgnoreCase))); |
| 1 | 234 | | } |
| 1 | 235 | | else |
| 1 | 236 | | { |
| 9 | 237 | | return Expression.Not(Expression.Call( |
| 9 | 238 | | context.PropertyValue, |
| 9 | 239 | | typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string) }), |
| 9 | 240 | | context.FilterValue)); |
| 1 | 241 | | } |
| 1 | 242 | | }) |
| 1 | 243 | | .IsStringBased() |
| 1 | 244 | | .Build(), |
| 1 | 245 | | new FilterOperatorBuilder() |
| 1 | 246 | | .HasSymbol(FilterOperatorSymbols.DoesNotEndWith) |
| 1 | 247 | | .HasName("does not end with") |
| 1 | 248 | | .HasExpression((context) => |
| 1 | 249 | | { |
| 18 | 250 | | if (context.IsMaterializedQueryable && context.IsCaseInsensitiveForValues) |
| 1 | 251 | | { |
| 9 | 252 | | return Expression.Not(Expression.Call( |
| 9 | 253 | | context.PropertyValue, |
| 9 | 254 | | typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string), typeof(String |
| 9 | 255 | | context.FilterValue, |
| 9 | 256 | | Expression.Constant(StringComparison.OrdinalIgnoreCase))); |
| 1 | 257 | | } |
| 1 | 258 | | else |
| 1 | 259 | | { |
| 9 | 260 | | return Expression.Not(Expression.Call( |
| 9 | 261 | | context.PropertyValue, |
| 9 | 262 | | typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string) }), |
| 9 | 263 | | context.FilterValue)); |
| 1 | 264 | | } |
| 1 | 265 | | }) |
| 1 | 266 | | .IsStringBased() |
| 1 | 267 | | .Build(), |
| 1 | 268 | | }; |
| | 269 | | } |
| | 270 | |
|
| | 271 | | private static IEnumerable<IFilterOperator> GetEqualCaseInsensitiveFilterOperators() |
| | 272 | | { |
| 1 | 273 | | return new List<IFilterOperator> |
| 1 | 274 | | { |
| 1 | 275 | | new FilterOperatorBuilder() |
| 1 | 276 | | .HasSymbol(FilterOperatorSymbols.EqualsCaseInsensitive) |
| 1 | 277 | | .HasName("equal (case insensitive)") |
| 1 | 278 | | .HasExpression((context) => |
| 1 | 279 | | { |
| 20 | 280 | | if (context.IsMaterializedQueryable) |
| 1 | 281 | | { |
| 10 | 282 | | return Expression.Call( |
| 10 | 283 | | typeof(string).GetMethod( |
| 10 | 284 | | nameof(string.Equals), |
| 10 | 285 | | BindingFlags.Static | BindingFlags.Public, |
| 10 | 286 | | null, |
| 10 | 287 | | new Type[] { typeof(string), typeof(string), typeof(StringComparison) }, |
| 10 | 288 | | null), |
| 10 | 289 | | context.PropertyValue, |
| 10 | 290 | | context.FilterValue, |
| 10 | 291 | | Expression.Constant(StringComparison.OrdinalIgnoreCase)); |
| 1 | 292 | | } |
| 1 | 293 | | else |
| 1 | 294 | | { |
| 10 | 295 | | return Expression.Call( |
| 10 | 296 | | typeof(string).GetMethod( |
| 10 | 297 | | nameof(string.Equals), |
| 10 | 298 | | BindingFlags.Static | BindingFlags.Public, |
| 10 | 299 | | null, |
| 10 | 300 | | new Type[] { typeof(string), typeof(string) }, |
| 10 | 301 | | null), |
| 10 | 302 | | context.PropertyValue, |
| 10 | 303 | | context.FilterValue); |
| 1 | 304 | | } |
| 1 | 305 | | }) |
| 1 | 306 | | .IsStringBased() |
| 1 | 307 | | .IsCaseInsensitive() |
| 1 | 308 | | .Build(), |
| 1 | 309 | | new FilterOperatorBuilder() |
| 1 | 310 | | .HasSymbol(FilterOperatorSymbols.DoesNotEqualCaseInsensitive) |
| 1 | 311 | | .HasName("does not equal (case insensitive)") |
| 1 | 312 | | .HasExpression((context) => |
| 1 | 313 | | { |
| 20 | 314 | | if (context.IsMaterializedQueryable) |
| 1 | 315 | | { |
| 10 | 316 | | return Expression.Not(Expression.Call( |
| 10 | 317 | | typeof(string).GetMethod( |
| 10 | 318 | | nameof(string.Equals), |
| 10 | 319 | | BindingFlags.Static | BindingFlags.Public, |
| 10 | 320 | | null, |
| 10 | 321 | | new Type[] { typeof(string), typeof(string), typeof(StringComparison) }, |
| 10 | 322 | | null), |
| 10 | 323 | | context.PropertyValue, |
| 10 | 324 | | context.FilterValue, |
| 10 | 325 | | Expression.Constant(StringComparison.OrdinalIgnoreCase))); |
| 1 | 326 | | } |
| 1 | 327 | | else |
| 1 | 328 | | { |
| 10 | 329 | | return Expression.Not(Expression.Call( |
| 10 | 330 | | typeof(string).GetMethod( |
| 10 | 331 | | nameof(string.Equals), |
| 10 | 332 | | BindingFlags.Static | BindingFlags.Public, |
| 10 | 333 | | null, |
| 10 | 334 | | new Type[] { typeof(string), typeof(string) }, |
| 10 | 335 | | null), |
| 10 | 336 | | context.PropertyValue, |
| 10 | 337 | | context.FilterValue)); |
| 1 | 338 | | } |
| 1 | 339 | | }) |
| 1 | 340 | | .IsStringBased() |
| 1 | 341 | | .IsCaseInsensitive() |
| 1 | 342 | | .Build(), |
| 1 | 343 | | }; |
| | 344 | | } |
| | 345 | |
|
| | 346 | | private static IEnumerable<IFilterOperator> GetStringCaseInsensitiveFilterOperators() |
| | 347 | | { |
| 1 | 348 | | return new List<IFilterOperator> |
| 1 | 349 | | { |
| 1 | 350 | | new FilterOperatorBuilder() |
| 1 | 351 | | .HasSymbol(FilterOperatorSymbols.ContainsCaseInsensitive) |
| 1 | 352 | | .HasName("contains (case insensitive)") |
| 1 | 353 | | .HasExpression((context) => |
| 1 | 354 | | { |
| 18 | 355 | | if (context.IsMaterializedQueryable) |
| 1 | 356 | | { |
| 9 | 357 | | return Expression.Call( |
| 9 | 358 | | context.PropertyValue, |
| 9 | 359 | | typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string), typeof(String |
| 9 | 360 | | context.FilterValue, |
| 9 | 361 | | Expression.Constant(StringComparison.OrdinalIgnoreCase)); |
| 1 | 362 | | } |
| 1 | 363 | | else |
| 1 | 364 | | { |
| 9 | 365 | | return Expression.Call( |
| 9 | 366 | | context.PropertyValue, |
| 9 | 367 | | typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string) }), |
| 9 | 368 | | context.FilterValue); |
| 1 | 369 | | } |
| 1 | 370 | | }) |
| 1 | 371 | | .IsStringBased() |
| 1 | 372 | | .IsCaseInsensitive() |
| 1 | 373 | | .Build(), |
| 1 | 374 | | new FilterOperatorBuilder() |
| 1 | 375 | | .HasSymbol(FilterOperatorSymbols.StartsWithCaseInsensitive) |
| 1 | 376 | | .HasName("starts with (case insensitive)") |
| 1 | 377 | | .HasExpression((context) => |
| 1 | 378 | | { |
| 18 | 379 | | if (context.IsMaterializedQueryable) |
| 1 | 380 | | { |
| 9 | 381 | | return Expression.Call( |
| 9 | 382 | | context.PropertyValue, |
| 9 | 383 | | typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string), typeof(Stri |
| 9 | 384 | | context.FilterValue, |
| 9 | 385 | | Expression.Constant(StringComparison.OrdinalIgnoreCase)); |
| 1 | 386 | | } |
| 1 | 387 | | else |
| 1 | 388 | | { |
| 9 | 389 | | return Expression.Call( |
| 9 | 390 | | context.PropertyValue, |
| 9 | 391 | | typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string) }), |
| 9 | 392 | | context.FilterValue); |
| 1 | 393 | | } |
| 1 | 394 | | }) |
| 1 | 395 | | .IsStringBased() |
| 1 | 396 | | .IsCaseInsensitive() |
| 1 | 397 | | .Build(), |
| 1 | 398 | | new FilterOperatorBuilder() |
| 1 | 399 | | .HasSymbol(FilterOperatorSymbols.EndsWithCaseInsensitive) |
| 1 | 400 | | .HasName("ends with (case insensitive)") |
| 1 | 401 | | .HasExpression((context) => |
| 1 | 402 | | { |
| 18 | 403 | | if (context.IsMaterializedQueryable) |
| 1 | 404 | | { |
| 9 | 405 | | return Expression.Call( |
| 9 | 406 | | context.PropertyValue, |
| 9 | 407 | | typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string), typeof(String |
| 9 | 408 | | context.FilterValue, |
| 9 | 409 | | Expression.Constant(StringComparison.OrdinalIgnoreCase)); |
| 1 | 410 | | } |
| 1 | 411 | | else |
| 1 | 412 | | { |
| 9 | 413 | | return Expression.Call( |
| 9 | 414 | | context.PropertyValue, |
| 9 | 415 | | typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string) }), |
| 9 | 416 | | context.FilterValue); |
| 1 | 417 | | } |
| 1 | 418 | | }) |
| 1 | 419 | | .IsStringBased() |
| 1 | 420 | | .IsCaseInsensitive() |
| 1 | 421 | | .Build(), |
| 1 | 422 | | }; |
| | 423 | | } |
| | 424 | |
|
| | 425 | | private static IEnumerable<IFilterOperator> GetStringNegatedCaseInsensitiveFilterOperators() |
| | 426 | | { |
| 1 | 427 | | return new List<IFilterOperator> |
| 1 | 428 | | { |
| 1 | 429 | | new FilterOperatorBuilder() |
| 1 | 430 | | .HasSymbol(FilterOperatorSymbols.DoesNotContainCaseInsensitive) |
| 1 | 431 | | .HasName("does not contain (case insensitive)") |
| 1 | 432 | | .HasExpression((context) => |
| 1 | 433 | | { |
| 18 | 434 | | if (context.IsMaterializedQueryable) |
| 1 | 435 | | { |
| 9 | 436 | | return Expression.Not(Expression.Call( |
| 9 | 437 | | context.PropertyValue, |
| 9 | 438 | | typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string), typeof(String |
| 9 | 439 | | context.FilterValue, |
| 9 | 440 | | Expression.Constant(StringComparison.OrdinalIgnoreCase))); |
| 1 | 441 | | } |
| 1 | 442 | | else |
| 1 | 443 | | { |
| 9 | 444 | | return Expression.Not(Expression.Call( |
| 9 | 445 | | context.PropertyValue, |
| 9 | 446 | | typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string) }), |
| 9 | 447 | | context.FilterValue)); |
| 1 | 448 | | } |
| 1 | 449 | | }) |
| 1 | 450 | | .IsStringBased() |
| 1 | 451 | | .IsCaseInsensitive() |
| 1 | 452 | | .Build(), |
| 1 | 453 | | new FilterOperatorBuilder() |
| 1 | 454 | | .HasSymbol(FilterOperatorSymbols.DoesNotStartWithCaseInsensitive) |
| 1 | 455 | | .HasName("does not start with (case insensitive)") |
| 1 | 456 | | .HasExpression((context) => |
| 1 | 457 | | { |
| 18 | 458 | | if (context.IsMaterializedQueryable) |
| 1 | 459 | | { |
| 9 | 460 | | return Expression.Not(Expression.Call( |
| 9 | 461 | | context.PropertyValue, |
| 9 | 462 | | typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string), typeof(Stri |
| 9 | 463 | | context.FilterValue, |
| 9 | 464 | | Expression.Constant(StringComparison.OrdinalIgnoreCase))); |
| 1 | 465 | | } |
| 1 | 466 | | else |
| 1 | 467 | | { |
| 9 | 468 | | return Expression.Not(Expression.Call( |
| 9 | 469 | | context.PropertyValue, |
| 9 | 470 | | typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string) }), |
| 9 | 471 | | context.FilterValue)); |
| 1 | 472 | | } |
| 1 | 473 | | }) |
| 1 | 474 | | .IsStringBased() |
| 1 | 475 | | .IsCaseInsensitive() |
| 1 | 476 | | .Build(), |
| 1 | 477 | | new FilterOperatorBuilder() |
| 1 | 478 | | .HasSymbol(FilterOperatorSymbols.DoesNotEndWithCaseInsensitive) |
| 1 | 479 | | .HasName("does not end with (case insensitive)") |
| 1 | 480 | | .HasExpression((context) => |
| 1 | 481 | | { |
| 18 | 482 | | if (context.IsMaterializedQueryable) |
| 1 | 483 | | { |
| 9 | 484 | | return Expression.Not(Expression.Call( |
| 9 | 485 | | context.PropertyValue, |
| 9 | 486 | | typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string), typeof(String |
| 9 | 487 | | context.FilterValue, |
| 9 | 488 | | Expression.Constant(StringComparison.OrdinalIgnoreCase))); |
| 1 | 489 | | } |
| 1 | 490 | | else |
| 1 | 491 | | { |
| 9 | 492 | | return Expression.Not(Expression.Call( |
| 9 | 493 | | context.PropertyValue, |
| 9 | 494 | | typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string) }), |
| 9 | 495 | | context.FilterValue)); |
| 1 | 496 | | } |
| 1 | 497 | | }) |
| 1 | 498 | | .IsStringBased() |
| 1 | 499 | | .IsCaseInsensitive() |
| 1 | 500 | | .Build(), |
| 1 | 501 | | }; |
| | 502 | | } |
| | 503 | | } |