Skip to content

Commit d3c60d7

Browse files
committed
fix: array
1 parent 7db5a4a commit d3c60d7

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

QueryKit/FilterParser.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
namespace QueryKit;
33

4+
using System.Collections;
45
using System.Globalization;
5-
using System.Linq;
66
using System.Linq.Expressions;
77
using System.Reflection;
88
using Configuration;
@@ -317,12 +317,35 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ
317317
return Expression.Constant(null, rawType);
318318
}
319319

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);
320344
var parsed = Enum.TryParse(enumType, right, out var enumValue);
321345
if (!parsed)
322346
{
323347
throw new InvalidOperationException($"Unsupported value '{right}' for type '{targetType.Name}'");
324348
}
325-
326349
var constant = Expression.Constant(enumValue, enumType);
327350

328351
if (rawType == enumType) return constant;

0 commit comments

Comments
 (0)