I have something like
Car:Vehicle {}
Truck:Vehicle {}
Database ORM return list that could contain either. Fetch < Vehicle > will lose sub class information. If I fetch object or dynamic, it will return list of ExpandoObject. Due the the underline framework restriction, I can't pass in generic T, only strings. So I have something like this:
Type type = Type.GetType("Car")
I can also create a typed List< Car > like so
var genericListType = typeof(List<>);
var specificListType = genericListType.MakeGenericType(type);
var list = Activator.CreateInstance(specificListType) as IList;
Not sure where to go from here. Reflection seems not very efficient, also can't add to IList. Any hint? Thanks.
Aucun commentaire:
Enregistrer un commentaire