Skip to content

Commit db3508c

Browse files
support params array when a parameter array with the right type is provided
1 parent d05fd59 commit db3508c

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55

66
<PropertyGroup>
7-
<VersionPrefix>1.1.3</VersionPrefix>
7+
<VersionPrefix>1.1.4</VersionPrefix>
88
</PropertyGroup>
99

1010
<Choose>

Z.Dynamic.Core.Lab/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Program
66
{
77
static void Main(string[] args)
88
{
9-
Request_Promote.Execute();
9+
Request_DynamicLinqType.Execute();
1010
}
1111
}
1212
}

Z.Dynamic.Core.Lab/Request_DynamicLinqType.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ public static void Execute()
4646
{"y", 2},
4747
};
4848

49-
var t1 = Utils.ConvertToArray(null);
49+
//var t1 = Utils.ConvertToArray(null);
5050

51-
string query = "Utils.ConvertToArray()";
52-
LambdaExpression expression = DynamicExpressionParser.ParseLambda(null, query, externals);
53-
Delegate del = expression.Compile();
54-
var result = del.DynamicInvoke();
55-
51+
//string query = "Utils.ConvertToArray()";
52+
//LambdaExpression expression = DynamicExpressionParser.ParseLambda(null, query, externals);
53+
//Delegate del = expression.Compile();
54+
//var result = del.DynamicInvoke();
55+
56+
var config = new ParsingConfig();
57+
58+
var list = new[] { new X { }, new X { Values = new[] { "a", "b" } } }.AsQueryable();
59+
var result = list.Select("Utils.ConvertToArray(Values)").ToDynamicList<string[]>();
60+
}
61+
62+
public class X
63+
{
64+
public string[] Values { get; set; }
5665
}
5766
}
5867
}

src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ bool IsApplicable(MethodData method, Expression[] args)
133133
{
134134
promotedArgs[promotedArgs.Length - 1] = Expression.Constant(null, method.Parameters.Last().ParameterType);
135135
}
136+
else if (method.Parameters.Length == args.Length && method.Parameters.Last().ParameterType == args.Last().Type)
137+
{
138+
promotedArgs[promotedArgs.Length - 1] = args.Last();
139+
}
136140
else
137141
{
138142
var paramType = method.Parameters.Last().ParameterType;

test/System.Linq.Dynamic.Core.Tests/Parser/DynamicLinqTypeTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public static string[] ConvertToArray(int a, params string[] values)
3030
}
3131
}
3232

33+
public class EntityValue
34+
{
35+
public string[] Values { get; set; }
36+
}
37+
3338

3439
[Fact]
3540
public void ParamArray_EmptyValue()
@@ -113,5 +118,17 @@ public void ParamArray_WithSingleValue2()
113118
Check.That(result.Length).Equals(1);
114119
Check.That(result[0]).Equals("a");
115120
}
121+
122+
[Fact]
123+
public void ParamArray_Array()
124+
{
125+
var list = new[] { new EntityValue { }, new EntityValue { Values = new[] { "a", "b" } } }.AsQueryable();
126+
var result = list.Select("Utils.ConvertToArray(Values)").ToDynamicList<string[]>();
127+
128+
Check.That(result.Count).Equals(2);
129+
Check.That(result[0]).IsNull();
130+
Check.That(result[1][0]).Equals("a");
131+
Check.That(result[1][1]).Equals("b");
132+
}
116133
}
117134
}

0 commit comments

Comments
 (0)