Sunday, 15 July 2012

.net - Find the generic type -


Is there a way to get it during reflection?
id works & lt ;, & gt; iDictionary & lt; Int, int & gt; , for example?

My intention is this:

  from typeof (uniqueKeyQuery & lt ;, & gt;) Query.GetType ())   

While the ' query ' type UniqueKeyQuery & lt; Sometype, int & gt; .
I want to compare names, because I would like to be Extensible Extensible.

You can try

  typeof (UniqueKeyQuery & lt; , & Gt;). IsAssignableFrom (query.GetType (). GetGenericDefitition ()) If this does not work, you can use it (a static extension method that should be in a fixed class)  
  Public Stable Boole ISO InheritsGeneric Definition (Type Type, Type Generic Definition, Parameter Typed with Out Type Definition) {DefinitionWithTypedParameters = ThisType; Whereas (with parameter plus parameter! = Null) {if (with the definition of the parameter .isgenic type) {if (with the definition of parameter .getgenic type definition == generic definition) return true; } Along with definitions, the published parameters = along with the definition. Parameter. Base type; } return false; }   

Call:

  Type query type; Query.GetType () IsOrInheritsGenericDefinition (typeof (uniquequaequery & lt ;, & gt;), QueryType out);    

No comments:

Post a Comment