jeudi 4 février 2016

Check T generic type has property S (generic) in c#

class A

class A{
...
}

class B

 class B:A{
    ...
 }

class C

 class C:A{
    B[] bArray{get;set;}
 }

I would like to check if T has a property type of S , create instance of S and assignment to that propery :

public Initial<T,S>() where T,S : A{
   if(T.has(typeof(S))){
      S s=new S();
      T.s=s;
   }
}





Aucun commentaire:

Enregistrer un commentaire