From c1b7ba3366d72decfb32dab99b72c0a5cb5193ce Mon Sep 17 00:00:00 2001 From: ZEXSM Date: Sun, 22 Nov 2020 21:53:37 +0300 Subject: [PATCH] #ZEXSM#bugfix use new array in the operator In --- .../Visitors/VisitorExpression.cs | 13 +++++++++++++ .../ODataQueryOptionListTest.cs | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/OData.QueryBuilder/Visitors/VisitorExpression.cs b/src/OData.QueryBuilder/Visitors/VisitorExpression.cs index 92ca5242..722d958d 100644 --- a/src/OData.QueryBuilder/Visitors/VisitorExpression.cs +++ b/src/OData.QueryBuilder/Visitors/VisitorExpression.cs @@ -241,6 +241,7 @@ protected virtual string VisitParameterExpression(ParameterExpression parameterE MemberExpression memberExpression => GetValueOfMemberExpression(memberExpression), ConstantExpression constantExpression => GetValueOfConstantExpression(constantExpression), ListInitExpression listInitExpression => GetValueOfListInitExpression(listInitExpression), + NewArrayExpression newArrayExpression => GetValueOfNewArrayExpression(newArrayExpression), _ => default, }; @@ -280,6 +281,18 @@ protected object GetValueOfListInitExpression(ListInitExpression listInitExpress return listInit; } + protected object GetValueOfNewArrayExpression(NewArrayExpression newArrayExpression) + { + var array = Array.CreateInstance(newArrayExpression.Type.GetElementType(), newArrayExpression.Expressions.Count); + + for (var i = 0; i < newArrayExpression.Expressions.Count; i++) + { + array.SetValue(GetValueOfExpression(newArrayExpression.Expressions[i]), i); + } + + return array; + } + protected bool IsResourceOfMemberExpression(MemberExpression memberExpression) => memberExpression.Expression switch { ParameterExpression pe => pe.Type.GetProperty(memberExpression.Member.Name, memberExpression.Type) != default, diff --git a/test/OData.QueryBuilder.Test/ODataQueryOptionListTest.cs b/test/OData.QueryBuilder.Test/ODataQueryOptionListTest.cs index c612ee01..8ceebeab 100644 --- a/test/OData.QueryBuilder.Test/ODataQueryOptionListTest.cs +++ b/test/OData.QueryBuilder.Test/ODataQueryOptionListTest.cs @@ -851,6 +851,18 @@ public void ODataQueryBuilderList_Operator_In_is_empty_1() .Should().Throw().WithMessage("Enumeration is empty or null"); } + [Fact(DisplayName = "Filter In operator with new => Success")] + public void ODataQueryBuilderList_Filter_In_with_new_Success() + { + var uri = _odataQueryBuilderDefault + .For(s => s.ODataType) + .ByList() + .Filter((s, f, o) => o.In(s.ODataKind.ODataCode.Code, new[] { "123", "512" }) && o.In(s.IdType, new[] { 123, 512 })) + .ToUri(); + + uri.OriginalString.Should().Be($"http://mock/odata/ODataType?$filter=ODataKind/ODataCode/Code in ('123','512') and IdType in (123,512)"); + } + [Fact(DisplayName = "Filter boolean values => Success")] public void ODataQueryBuilderList_Filter_Boolean_Values_Success() {