lundi 17 octobre 2016

How to cast object to EntitySet with variable generic

I have a variable (type: object) called o. I also have a variable (type: Type) called t. I know that o is an EntitySet with the type of t with a single entry in it.

I need to get the first element in the EntitySet so that I can use reflection on it to get it's propertys. Have tried a couple of approaches to getting the first element, but none have worked.

  1. Cast o to EntitySet - sounds good but dont know how to do this with t being a variable that can change
  2. Cast o to dynamic
  3. Cast o to EntitySet - The intention is that then I can use the methods of EntitySet and get first object but it throws an exception

Have:

Type t;    
object o; // we know it's EntitySet<t>

I need

t firstElement = o[0];





Aucun commentaire:

Enregistrer un commentaire