This project has moved and is read-only. For the latest updates, please go here.

Convert ExpandoObject to typed list without generic T

Feb 13, 2015 at 10:44 PM
I query database and get a list of ExpandoObject. Due to framework restriction, can't pass in generic T. The best I can get is

Type type = typeof(MyType).Assembly.GetType("SomeType");

Is there a quick and easy way to cast the expando list to a typed list using FasterFlect? I tried TryCreateInstance, but got either missing field or object null reference.
Feb 16, 2015 at 6:40 PM
The best I can do so far is type.CreateInstance, then loop through the dictionary and TrySetPropertyValue. Wonder if there's something even better.
Feb 16, 2015 at 7:22 PM
Edited Feb 16, 2015 at 9:01 PM
Nevermind, turned out the micro ORM I used, schotime/NPoco has this built in.

Type type = typeof(Vehicle).Assembly.GetType("Car");
var cars = db.Query<Vehicle>(new[] { type }, null, new Sql("select * from cars"));
Marked as answer by whoever on 2/16/2015 at 11:22 AM