Skip to content
Permalink
Browse files

Fixed issue #129

  • Loading branch information...
StefH committed Dec 15, 2017
1 parent cb11c82 commit 4d1e5dcab53b57207e51c58b1d4e800063d4e46d
@@ -11,6 +11,14 @@ static void Main(string[] args)
{
using (var db = new MyDbContext())
{
var all = new
{
test1 = new List<int> { 1, 2, 3 }.ToDynamicList(typeof(int)),
test2 = new List<dynamic> { 4, 5, 6 }.ToDynamicList(typeof(int)),
test3 = new List<object> { 7, 8, 9 }.ToDynamicList(typeof(int))
};
Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));

var persons = new List<Person>
{
new Person { Name = "a", Age = 18, Address = new Address { Street = "s1" } },
@@ -27,6 +27,14 @@ public HashSet<Type> GetCustomTypes()

static void Main(string[] args)
{
var all = new
{
test1 = new List<int> { 1, 2, 3 }.ToDynamicList(typeof(int)),
test2 = new List<dynamic> { 4, 5, 6 }.ToDynamicList(typeof(int)),
test3 = new List<object> { 7, 8, 9 }.ToDynamicList(typeof(int))
};
Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));

var config = new ParsingConfig();
config.CustomTypeProvider = new C();

@@ -62,6 +62,9 @@
<Reference Include="Linq.Expression.Optimizer, Version=1.0.6.0, Culture=neutral, PublicKeyToken=34b6af2337893e15, processorArchitecture=MSIL">
<HintPath>..\..\packages\Linq.Expression.Optimizer.1.0.9\lib\net45\Linq.Expression.Optimizer.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
@@ -1,14 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ConsoleApp_net452_EF6.Entities;
using System.Linq.Dynamic.Core;
using Newtonsoft.Json;

namespace ConsoleApp_net452_EF6
{
class Program
{
static void Main(string[] args)
{
var all = new
{
test1 = new List<int> { 1, 2, 3 }.ToDynamicList(typeof(int)),
test2 = new List<dynamic> { 4, 5, 6 }.ToDynamicList(typeof(int)),
test3 = new List<object> { 7, 8, 9 }.ToDynamicList(typeof(int))
};

Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));
using (var context = new KendoGridDbContext())
{
string search = "2";
@@ -3,4 +3,5 @@
<package id="EntityFramework" version="6.2.0" targetFramework="net452" />
<package id="FSharp.Core" version="4.2.3" targetFramework="net452" />
<package id="Linq.Expression.Optimizer" version="1.0.9" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
</packages>
@@ -65,11 +65,11 @@ public static dynamic[] ToDynamicArray([NotNull] this IEnumerable source, [NotNu
Check.NotNull(source, nameof(source));
Check.NotNull(type, nameof(type));

object result = ToDynamicArrayGenericMethod.MakeGenericMethod(type).Invoke(source, new object[] { source });
IEnumerable result = (IEnumerable)ToDynamicArrayGenericMethod.MakeGenericMethod(type).Invoke(source, new object[] { source });
#if NET35
return (object[])result;
return CastToArray<object>(result);
#else
return (dynamic[])result;
return CastToArray<dynamic>(result);
#endif
}

@@ -132,4 +132,4 @@ internal static List<T> CastToList<T>(IEnumerable source)
return source.Cast<T>().ToList();
}
}
}
}
@@ -0,0 +1,39 @@
using System.Collections.Generic;
using NFluent;
using Xunit;

namespace System.Linq.Dynamic.Core.Tests
{
public class DynamicEnumerableExtensionsTests
{
[Fact]
public void DynamicEnumerableExtensions_ToDynamicArray_int_to_int()
{
// Act
var result = new List<int> { 0, 1 }.ToDynamicList(typeof(int));

// Assert
Check.That(result).ContainsExactly(0, 1);
}

[Fact]
public void DynamicEnumerableExtensions_ToDynamicArray_dynamic_to_int()
{
// Act
var result = new List<dynamic> { 0, 1 }.ToDynamicList(typeof(int));

// Assert
Check.That(result).ContainsExactly(0, 1);
}

[Fact]
public void DynamicEnumerableExtensions_ToDynamicArray_object_to_int()
{
// Act
var result = new List<object> { 0, 1 }.ToDynamicList(typeof(int));

// Assert
Check.That(result).ContainsExactly(0, 1);
}
}
}

0 comments on commit 4d1e5dc

Please sign in to comment.
You can’t perform that action at this time.