Skip to content

Commit 4d1e5dc

Browse files
committed
Fixed issue #129
1 parent cb11c82 commit 4d1e5dc

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed

src-console/ConsoleAppEF1.1/Program.cs

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ static void Main(string[] args)
1111
{
1212
using (var db = new MyDbContext())
1313
{
14+
var all = new
15+
{
16+
test1 = new List<int> { 1, 2, 3 }.ToDynamicList(typeof(int)),
17+
test2 = new List<dynamic> { 4, 5, 6 }.ToDynamicList(typeof(int)),
18+
test3 = new List<object> { 7, 8, 9 }.ToDynamicList(typeof(int))
19+
};
20+
Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));
21+
1422
var persons = new List<Person>
1523
{
1624
new Person { Name = "a", Age = 18, Address = new Address { Street = "s1" } },

src-console/ConsoleAppEF2.0/Program.cs

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public HashSet<Type> GetCustomTypes()
2727

2828
static void Main(string[] args)
2929
{
30+
var all = new
31+
{
32+
test1 = new List<int> { 1, 2, 3 }.ToDynamicList(typeof(int)),
33+
test2 = new List<dynamic> { 4, 5, 6 }.ToDynamicList(typeof(int)),
34+
test3 = new List<object> { 7, 8, 9 }.ToDynamicList(typeof(int))
35+
};
36+
Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));
37+
3038
var config = new ParsingConfig();
3139
config.CustomTypeProvider = new C();
3240

src-console/ConsoleApp_net452_EF6/ConsoleApp_net452_EF6.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
<Reference Include="Linq.Expression.Optimizer, Version=1.0.6.0, Culture=neutral, PublicKeyToken=34b6af2337893e15, processorArchitecture=MSIL">
6363
<HintPath>..\..\packages\Linq.Expression.Optimizer.1.0.9\lib\net45\Linq.Expression.Optimizer.dll</HintPath>
6464
</Reference>
65+
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
66+
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
67+
</Reference>
6568
<Reference Include="System" />
6669
<Reference Include="System.ComponentModel.DataAnnotations" />
6770
<Reference Include="System.Core" />

src-console/ConsoleApp_net452_EF6/Program.cs

+10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using ConsoleApp_net452_EF6.Entities;
45
using System.Linq.Dynamic.Core;
6+
using Newtonsoft.Json;
57

68
namespace ConsoleApp_net452_EF6
79
{
810
class Program
911
{
1012
static void Main(string[] args)
1113
{
14+
var all = new
15+
{
16+
test1 = new List<int> { 1, 2, 3 }.ToDynamicList(typeof(int)),
17+
test2 = new List<dynamic> { 4, 5, 6 }.ToDynamicList(typeof(int)),
18+
test3 = new List<object> { 7, 8, 9 }.ToDynamicList(typeof(int))
19+
};
20+
21+
Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));
1222
using (var context = new KendoGridDbContext())
1323
{
1424
string search = "2";

src-console/ConsoleApp_net452_EF6/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<package id="EntityFramework" version="6.2.0" targetFramework="net452" />
44
<package id="FSharp.Core" version="4.2.3" targetFramework="net452" />
55
<package id="Linq.Expression.Optimizer" version="1.0.9" targetFramework="net452" />
6+
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
67
</packages>

src/System.Linq.Dynamic.Core/DynamicEnumerableExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public static dynamic[] ToDynamicArray([NotNull] this IEnumerable source, [NotNu
6565
Check.NotNull(source, nameof(source));
6666
Check.NotNull(type, nameof(type));
6767

68-
object result = ToDynamicArrayGenericMethod.MakeGenericMethod(type).Invoke(source, new object[] { source });
68+
IEnumerable result = (IEnumerable)ToDynamicArrayGenericMethod.MakeGenericMethod(type).Invoke(source, new object[] { source });
6969
#if NET35
70-
return (object[])result;
70+
return CastToArray<object>(result);
7171
#else
72-
return (dynamic[])result;
72+
return CastToArray<dynamic>(result);
7373
#endif
7474
}
7575

@@ -132,4 +132,4 @@ internal static List<T> CastToList<T>(IEnumerable source)
132132
return source.Cast<T>().ToList();
133133
}
134134
}
135-
}
135+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using NFluent;
3+
using Xunit;
4+
5+
namespace System.Linq.Dynamic.Core.Tests
6+
{
7+
public class DynamicEnumerableExtensionsTests
8+
{
9+
[Fact]
10+
public void DynamicEnumerableExtensions_ToDynamicArray_int_to_int()
11+
{
12+
// Act
13+
var result = new List<int> { 0, 1 }.ToDynamicList(typeof(int));
14+
15+
// Assert
16+
Check.That(result).ContainsExactly(0, 1);
17+
}
18+
19+
[Fact]
20+
public void DynamicEnumerableExtensions_ToDynamicArray_dynamic_to_int()
21+
{
22+
// Act
23+
var result = new List<dynamic> { 0, 1 }.ToDynamicList(typeof(int));
24+
25+
// Assert
26+
Check.That(result).ContainsExactly(0, 1);
27+
}
28+
29+
[Fact]
30+
public void DynamicEnumerableExtensions_ToDynamicArray_object_to_int()
31+
{
32+
// Act
33+
var result = new List<object> { 0, 1 }.ToDynamicList(typeof(int));
34+
35+
// Assert
36+
Check.That(result).ContainsExactly(0, 1);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)