Inherited Enumerable Support
The code can now support to create expressions with class inheriting IEnumerable.
class Foo
{
}
class ListOfFoo : List<Foo>
{
}
[TestMethod]
public void TestInheritanceOfListAsGenericEnumerableType()
{
var shouldBeTrue = QueryableHelpers.IsGenericEnumerable(typeof(ListOfFoo));
Assert.IsTrue(shouldBeTrue);
var type = QueryableHelpers.GetTypeOfEnumerable(typeof(ListOfFoo), true);
Assert.IsTrue(type == typeof(Foo));
}
Allows
public class MockPerson
{
public string Name { get; set; }
public MockListOfPhone Phones { get; set; }
}
public class MockPhone
{
public string Number { get; set; }
}
public class MockListOfPhone : List<MockPhone>
{
}
[TestMethod]
public void TestSelectWithInheritedList()
{
var list = new List<MockPerson>()
{
new MockPerson
{
Name = "David Lebee",
Phones = new MockListOfPhone
{
new MockPhone
{
Number = "0000000000"
}
}
},
new MockPerson
{
Name = "Yubing Liang",
Phones = new MockListOfPhone
{
new MockPhone
{
Number = "1111111111"
}
}
}
};
var names = list.AsQueryable()
.Where(t => t.Equal("Phones.Number", "1111111111"))
.Select(t =>
{
t.Path("Name");
t.FirstOrDefault("Phones.Number", "Number", SelectCollectionHandling.Flatten);
})
.ToDynamicClassList();
Assert.IsTrue(names.Count() == 1);
var firstPerson = names.First();
Assert.AreEqual("Yubing Liang", firstPerson.GetDynamicPropertyValue<string>("Name"));
Assert.AreEqual("1111111111", firstPerson.GetDynamicPropertyValue<string>("Number"));
}