Skip to content

Commit ded6619

Browse files
authored
Add Json support (#791)
Add Json support (#791)
1 parent 9d489d2 commit ded6619

File tree

39 files changed

+4124
-31546
lines changed

39 files changed

+4124
-31546
lines changed

.github/workflows/ci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ jobs:
8585
run: |
8686
dotnet-coverage collect 'dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj --configuration Debug --framework net8.0 -p:buildType=azure-pipelines-ci' -f xml -o dynamic-coverage-efcore.xml
8787
88+
- name: Run Tests Newtonsoft.Json .NET 8 (with Coverage)
89+
run: |
90+
dotnet-coverage collect 'dotnet test ./test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/System.Linq.Dynamic.Core.NewtonsoftJson.Tests.csproj --configuration Debug --framework net8.0 -p:buildType=azure-pipelines-ci' -f xml -o dynamic-coverage-newtonsoftjson.xml
91+
92+
- name: Run Tests System.Text.Json .NET 8 (with Coverage)
93+
run: |
94+
dotnet-coverage collect 'dotnet test ./test/System.Linq.Dynamic.Core.SystemTextJson.Tests/System.Linq.Dynamic.Core.SystemTextJson.Tests.csproj --configuration Debug --framework net8.0 -p:buildType=azure-pipelines-ci' -f xml -o dynamic-coverage-systemtextjson.xml
95+
8896
- name: End analysis on SonarCloud
8997
if: ${{ steps.secret-check.outputs.run_analysis == 'true' }}
9098
run: |

System.Linq.Dynamic.Core.sln

+76
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.Plugin", "src-console\
143143
EndProject
144144
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.Tests.NetCoreApp31", "test\System.Linq.Dynamic.Core.Tests.NetCoreApp31\System.Linq.Dynamic.Core.Tests.NetCoreApp31.csproj", "{7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}"
145145
EndProject
146+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.NewtonsoftJson", "src\System.Linq.Dynamic.Core.NewtonsoftJson\System.Linq.Dynamic.Core.NewtonsoftJson.csproj", "{8C5851B8-5C47-4229-AB55-D4252703598E}"
147+
EndProject
148+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.NewtonsoftJson.Tests", "test\System.Linq.Dynamic.Core.NewtonsoftJson.Tests\System.Linq.Dynamic.Core.NewtonsoftJson.Tests.csproj", "{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}"
149+
EndProject
150+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.SystemTextJson", "src\System.Linq.Dynamic.Core.SystemTextJson\System.Linq.Dynamic.Core.SystemTextJson.csproj", "{FA01CE15-315A-499E-AFC2-955CA7EB45FF}"
151+
EndProject
152+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.SystemTextJson.Tests", "test\System.Linq.Dynamic.Core.SystemTextJson.Tests\System.Linq.Dynamic.Core.SystemTextJson.Tests.csproj", "{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}"
153+
EndProject
146154
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WasmDynamicLinq", "src-blazor\WasmDynamicLinq\WasmDynamicLinq.csproj", "{2DE2052F-0A50-40C7-B6FF-52B52386BF9A}"
147155
EndProject
148156
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SldcTrimmer", "src-examples\SldcTrimmer\SldcTrimmer.csproj", "{7A31366C-DD98-41A3-A0C1-A97068BD9658}"
@@ -903,6 +911,70 @@ Global
903911
{7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|x64.Build.0 = Release|Any CPU
904912
{7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|x86.ActiveCfg = Release|Any CPU
905913
{7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|x86.Build.0 = Release|Any CPU
914+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
915+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Debug|Any CPU.Build.0 = Debug|Any CPU
916+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Debug|ARM.ActiveCfg = Debug|Any CPU
917+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Debug|ARM.Build.0 = Debug|Any CPU
918+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Debug|x64.ActiveCfg = Debug|Any CPU
919+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Debug|x64.Build.0 = Debug|Any CPU
920+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Debug|x86.ActiveCfg = Debug|Any CPU
921+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Debug|x86.Build.0 = Debug|Any CPU
922+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Release|Any CPU.ActiveCfg = Release|Any CPU
923+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Release|Any CPU.Build.0 = Release|Any CPU
924+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Release|ARM.ActiveCfg = Release|Any CPU
925+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Release|ARM.Build.0 = Release|Any CPU
926+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Release|x64.ActiveCfg = Release|Any CPU
927+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Release|x64.Build.0 = Release|Any CPU
928+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Release|x86.ActiveCfg = Release|Any CPU
929+
{8C5851B8-5C47-4229-AB55-D4252703598E}.Release|x86.Build.0 = Release|Any CPU
930+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
931+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Debug|Any CPU.Build.0 = Debug|Any CPU
932+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Debug|ARM.ActiveCfg = Debug|Any CPU
933+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Debug|ARM.Build.0 = Debug|Any CPU
934+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Debug|x64.ActiveCfg = Debug|Any CPU
935+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Debug|x64.Build.0 = Debug|Any CPU
936+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Debug|x86.ActiveCfg = Debug|Any CPU
937+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Debug|x86.Build.0 = Debug|Any CPU
938+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Release|Any CPU.ActiveCfg = Release|Any CPU
939+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Release|Any CPU.Build.0 = Release|Any CPU
940+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Release|ARM.ActiveCfg = Release|Any CPU
941+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Release|ARM.Build.0 = Release|Any CPU
942+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Release|x64.ActiveCfg = Release|Any CPU
943+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Release|x64.Build.0 = Release|Any CPU
944+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Release|x86.ActiveCfg = Release|Any CPU
945+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90}.Release|x86.Build.0 = Release|Any CPU
946+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
947+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
948+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Debug|ARM.ActiveCfg = Debug|Any CPU
949+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Debug|ARM.Build.0 = Debug|Any CPU
950+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Debug|x64.ActiveCfg = Debug|Any CPU
951+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Debug|x64.Build.0 = Debug|Any CPU
952+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Debug|x86.ActiveCfg = Debug|Any CPU
953+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Debug|x86.Build.0 = Debug|Any CPU
954+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
955+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Release|Any CPU.Build.0 = Release|Any CPU
956+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Release|ARM.ActiveCfg = Release|Any CPU
957+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Release|ARM.Build.0 = Release|Any CPU
958+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Release|x64.ActiveCfg = Release|Any CPU
959+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Release|x64.Build.0 = Release|Any CPU
960+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Release|x86.ActiveCfg = Release|Any CPU
961+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF}.Release|x86.Build.0 = Release|Any CPU
962+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
963+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
964+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Debug|ARM.ActiveCfg = Debug|Any CPU
965+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Debug|ARM.Build.0 = Debug|Any CPU
966+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Debug|x64.ActiveCfg = Debug|Any CPU
967+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Debug|x64.Build.0 = Debug|Any CPU
968+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Debug|x86.ActiveCfg = Debug|Any CPU
969+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Debug|x86.Build.0 = Debug|Any CPU
970+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
971+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Release|Any CPU.Build.0 = Release|Any CPU
972+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Release|ARM.ActiveCfg = Release|Any CPU
973+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Release|ARM.Build.0 = Release|Any CPU
974+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Release|x64.ActiveCfg = Release|Any CPU
975+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Release|x64.Build.0 = Release|Any CPU
976+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Release|x86.ActiveCfg = Release|Any CPU
977+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E}.Release|x86.Build.0 = Release|Any CPU
906978
{2DE2052F-0A50-40C7-B6FF-52B52386BF9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
907979
{2DE2052F-0A50-40C7-B6FF-52B52386BF9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
908980
{2DE2052F-0A50-40C7-B6FF-52B52386BF9A}.Debug|ARM.ActiveCfg = Debug|Any CPU
@@ -1018,6 +1090,10 @@ Global
10181090
{D8368319-F370-4071-9411-A3DADB234330} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
10191091
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
10201092
{7AFC2836-0F6E-4B0D-8BB3-13317A3B6616} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
1093+
{8C5851B8-5C47-4229-AB55-D4252703598E} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F}
1094+
{912FBF24-3CAE-4A50-B5EA-E525B9FAEC90} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
1095+
{FA01CE15-315A-499E-AFC2-955CA7EB45FF} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F}
1096+
{D5844AE4-53FA-4C8A-9D52-AD213FD0CA1E} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
10211097
{2DE2052F-0A50-40C7-B6FF-52B52386BF9A} = {122BC4FA-7563-4E35-9D17-077F16F1629F}
10221098
{7A31366C-DD98-41A3-A0C1-A97068BD9658} = {BCA2A024-9032-4E56-A6C4-17A15D921728}
10231099
{C774DAE7-54A0-4FCD-A3B7-3CB63D7E112D} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F}

src-console/ConsoleApp_net6.0/ConsoleApp_net6.0.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.csproj" />
11+
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core.NewtonsoftJson\System.Linq.Dynamic.Core.NewtonsoftJson.csproj" />
12+
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core.SystemTextJson\System.Linq.Dynamic.Core.SystemTextJson.csproj" />
1213
</ItemGroup>
1314

1415
</Project>

src-console/ConsoleApp_net6.0/Program.cs

+147-78
Original file line numberDiff line numberDiff line change
@@ -2,116 +2,185 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Linq.Dynamic.Core;
5-
using System.Linq.Dynamic.Core.Parser;
5+
using System.Linq.Dynamic.Core.NewtonsoftJson;
6+
using System.Linq.Dynamic.Core.SystemTextJson;
67
using System.Linq.Expressions;
8+
using System.Text.Json;
9+
using Newtonsoft.Json.Linq;
710

8-
namespace ConsoleApp_net6._0
11+
namespace ConsoleApp_net6._0;
12+
13+
public class X
914
{
10-
public class X
11-
{
12-
public string Key { get; set; } = null!;
15+
public string Key { get; set; } = null!;
1316

14-
public List<Y>? Contestants { get; set; }
15-
}
17+
public List<Y>? Contestants { get; set; }
18+
}
1619

17-
public class Y
20+
public class Y
21+
{
22+
}
23+
24+
class Program
25+
{
26+
static void Main(string[] args)
1827
{
28+
Json();
29+
NewtonsoftJson();
30+
31+
return;
32+
33+
Issue389DoesNotWork();
34+
return;
35+
Issue389_Works();
36+
return;
37+
38+
var q = new[]
39+
{
40+
new X { Key = "x" },
41+
new X { Key = "a" },
42+
new X { Key = "a", Contestants = new List<Y> { new Y() } }
43+
}.AsQueryable();
44+
var groupByKey = q.GroupBy("Key");
45+
var selectQry = groupByKey.Select("new (Key, Sum(np(Contestants.Count, 0)) As TotalCount)").ToDynamicList();
46+
47+
Normal();
48+
Dynamic();
1949
}
2050

21-
class Program
51+
private static void NewtonsoftJson()
2252
{
23-
static void Main(string[] args)
53+
var array = JArray.Parse(@"[
2454
{
25-
var parser = new ExpressionParser(new[] { Expression.Parameter(typeof(int), "VarA") }, "\"foo\" & VarA", new object[0], new ParsingConfig { ConvertObjectToSupportComparison = true});
26-
27-
var expression = parser.Parse(typeof(string));
28-
29-
Issue389DoesNotWork();
30-
return;
31-
Issue389_Works();
32-
return;
33-
34-
var q = new[]
35-
{
36-
new X { Key = "x" },
37-
new X { Key = "a" },
38-
new X { Key = "a", Contestants = new List<Y> { new Y() } }
39-
}.AsQueryable();
40-
var groupByKey = q.GroupBy("Key");
41-
var selectQry = groupByKey.Select("new (Key, Sum(np(Contestants.Count, 0)) As TotalCount)").ToDynamicList();
42-
43-
Normal();
44-
Dynamic();
45-
}
46-
47-
private static void Issue389_Works()
55+
""first"": 1,
56+
""City"": ""Paris"",
57+
""third"": ""test""
58+
},
4859
{
49-
var strArray = new[] { "1", "2", "3", "4" };
50-
var x = new List<ParameterExpression>();
51-
x.Add(Expression.Parameter(strArray.GetType(), "strArray"));
60+
""first"": 2,
61+
""City"": ""New York"",
62+
""third"": ""abc""
63+
}]");
5264

53-
string query = "string.Join(\",\", strArray)";
65+
var where = array.Where("City == @0", "Paris");
66+
foreach (var result in where)
67+
{
68+
Console.WriteLine(result["first"]);
69+
}
5470

55-
var e = DynamicExpressionParser.ParseLambda(x.ToArray(), null, query);
56-
Delegate del = e.Compile();
57-
var result1 = del.DynamicInvoke(new object?[] { strArray });
58-
Console.WriteLine(result1);
71+
var select = array.Select("City");
72+
foreach (var result in select)
73+
{
74+
Console.WriteLine(result);
5975
}
6076

61-
private static void Issue389WorksWithInts()
77+
var whereWithSelect = array.Where("City == @0", "Paris").Select("first");
78+
foreach (var result in whereWithSelect)
6279
{
63-
var intArray = new object[] { 1, 2, 3, 4 };
64-
var x = new List<ParameterExpression>();
65-
x.Add(Expression.Parameter(intArray.GetType(), "intArray"));
80+
Console.WriteLine(result);
81+
}
82+
}
6683

67-
string query = "string.Join(\",\", intArray)";
84+
private static void Json()
85+
{
86+
var doc = JsonDocument.Parse(@"[
87+
{
88+
""first"": 1,
89+
""City"": ""Paris"",
90+
""third"": ""test""
91+
},
92+
{
93+
""first"": 2,
94+
""City"": ""New York"",
95+
""third"": ""abc""
96+
}]");
6897

69-
var e = DynamicExpressionParser.ParseLambda(x.ToArray(), null, query);
70-
Delegate del = e.Compile();
71-
var result = del.DynamicInvoke(new object?[] { intArray });
98+
var where = doc.Where("City == @0", "Paris");
99+
foreach (var result in where.RootElement.EnumerateArray())
100+
{
101+
Console.WriteLine(result.GetProperty("first"));
102+
}
72103

104+
var select = doc.Select("City");
105+
foreach (var result in select.RootElement.EnumerateArray())
106+
{
73107
Console.WriteLine(result);
74108
}
75109

76-
private static void Issue389DoesNotWork()
110+
var whereWithSelect = doc.Where("City == @0", "Paris").Select("first");
111+
foreach (var result in whereWithSelect.RootElement.EnumerateArray())
77112
{
78-
var intArray = new [] { 1, 2, 3, 4 };
79-
var x = new List<ParameterExpression>();
80-
x.Add(Expression.Parameter(intArray.GetType(), "intArray"));
113+
Console.WriteLine(result);
114+
}
115+
}
81116

82-
string query = "string.Join(\",\", intArray)";
117+
private static void Issue389_Works()
118+
{
119+
var strArray = new[] { "1", "2", "3", "4" };
120+
var x = new List<ParameterExpression>();
121+
x.Add(Expression.Parameter(strArray.GetType(), "strArray"));
83122

84-
var e = DynamicExpressionParser.ParseLambda(x.ToArray(), null, query);
85-
Delegate del = e.Compile();
86-
var result = del.DynamicInvoke(new object?[] { intArray });
123+
string query = "string.Join(\",\", strArray)";
87124

88-
Console.WriteLine(result);
89-
}
125+
var e = DynamicExpressionParser.ParseLambda(x.ToArray(), null, query);
126+
Delegate del = e.Compile();
127+
var result1 = del.DynamicInvoke(new object?[] { strArray });
128+
Console.WriteLine(result1);
129+
}
90130

91-
private static void Normal()
92-
{
93-
var e = new int[0].AsQueryable();
94-
var q = new[] { 1 }.AsQueryable();
131+
private static void Issue389WorksWithInts()
132+
{
133+
var intArray = new object[] { 1, 2, 3, 4 };
134+
var x = new List<ParameterExpression>();
135+
x.Add(Expression.Parameter(intArray.GetType(), "intArray"));
95136

96-
var a = q.FirstOrDefault();
97-
var b = e.FirstOrDefault(44);
137+
string query = "string.Join(\",\", intArray)";
98138

99-
var c = q.FirstOrDefault(i => i == 0);
100-
var d = q.FirstOrDefault(i => i == 0, 42);
139+
var e = DynamicExpressionParser.ParseLambda(x.ToArray(), null, query);
140+
Delegate del = e.Compile();
141+
var result = del.DynamicInvoke(new object?[] { intArray });
101142

102-
var t = q.Take(1);
103-
}
143+
Console.WriteLine(result);
144+
}
104145

105-
private static void Dynamic()
106-
{
107-
var e = new int[0].AsQueryable() as IQueryable;
108-
var q = new[] { 1 }.AsQueryable() as IQueryable;
146+
private static void Issue389DoesNotWork()
147+
{
148+
var intArray = new[] { 1, 2, 3, 4 };
149+
var x = new List<ParameterExpression>();
150+
x.Add(Expression.Parameter(intArray.GetType(), "intArray"));
109151

110-
var a = q.FirstOrDefault();
111-
//var b = e.FirstOrDefault(44);
152+
string query = "string.Join(\",\", intArray)";
112153

113-
var c = q.FirstOrDefault("it == 0");
114-
//var d = q.FirstOrDefault(i => i == 0, 42);
115-
}
154+
var e = DynamicExpressionParser.ParseLambda(x.ToArray(), null, query);
155+
Delegate del = e.Compile();
156+
var result = del.DynamicInvoke(new object?[] { intArray });
157+
158+
Console.WriteLine(result);
159+
}
160+
161+
private static void Normal()
162+
{
163+
var e = new int[0].AsQueryable();
164+
var q = new[] { 1 }.AsQueryable();
165+
166+
var a = q.FirstOrDefault();
167+
var b = e.FirstOrDefault(44);
168+
169+
var c = q.FirstOrDefault(i => i == 0);
170+
var d = q.FirstOrDefault(i => i == 0, 42);
171+
172+
var t = q.Take(1);
173+
}
174+
175+
private static void Dynamic()
176+
{
177+
var e = new int[0].AsQueryable() as IQueryable;
178+
var q = new[] { 1 }.AsQueryable() as IQueryable;
179+
180+
var a = q.FirstOrDefault();
181+
//var b = e.FirstOrDefault(44);
182+
183+
var c = q.FirstOrDefault("it == 0");
184+
//var d = q.FirstOrDefault(i => i == 0, 42);
116185
}
117186
}

0 commit comments

Comments
 (0)