|
1 | 1 | |
2 | 2 | namespace QueryKit; |
3 | 3 |
|
| 4 | +using System.Collections; |
4 | 5 | using System.Globalization; |
5 | | -using System.Linq; |
6 | 6 | using System.Linq.Expressions; |
7 | 7 | using System.Reflection; |
8 | 8 | using Configuration; |
@@ -317,12 +317,35 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ |
317 | 317 | return Expression.Constant(null, rawType); |
318 | 318 | } |
319 | 319 |
|
| 320 | + if (right.StartsWith("[") && right.EndsWith("]")) |
| 321 | + |
| 322 | + { |
| 323 | + var values = right.Trim('[', ']').Split(',').Select(x => x.Trim()).ToList(); |
| 324 | + var elementType = targetType.IsArray ? targetType.GetElementType() : targetType; |
| 325 | + |
| 326 | + var expressions = values.Select<string, Expression>(x => |
| 327 | + { |
| 328 | + if (elementType == typeof(string) && x.StartsWith("\"") && x.EndsWith("\"")) |
| 329 | + { |
| 330 | + x = x.Trim('"'); |
| 331 | + } |
| 332 | + |
| 333 | + var enumValue = Enum.Parse(enumType, x); |
| 334 | + var constant = Expression.Constant(enumValue, enumType); |
| 335 | + |
| 336 | + return constant; |
| 337 | + }).ToArray(); |
| 338 | + |
| 339 | + var newArrayExpression = Expression.NewArrayInit(enumType, expressions); |
| 340 | + return newArrayExpression; |
| 341 | + } |
| 342 | + |
| 343 | + // var enumValue = Enum.Parse(enumType, right); |
320 | 344 | var parsed = Enum.TryParse(enumType, right, out var enumValue); |
321 | 345 | if (!parsed) |
322 | 346 | { |
323 | 347 | throw new InvalidOperationException($"Unsupported value '{right}' for type '{targetType.Name}'"); |
324 | 348 | } |
325 | | - |
326 | 349 | var constant = Expression.Constant(enumValue, enumType); |
327 | 350 |
|
328 | 351 | if (rawType == enumType) return constant; |
|
0 commit comments