reflection - How to check that type is inherited from some interface c# -


i have following:

assembly asm = assembly.getassembly(this.gettype());  foreach (type type in asm.gettypes()) {     myattribute attr = attribute.getcustomattribute(type, typeof(myattribute))    myattribute;      if(attr != null && [type inherited iinterface])      {         ...      }  } 

how can check type inherited myinterface? keywork work in way?

thank you.

no, is works checking type of object, not given type. want type.isassignablefrom:

if (attr != null && typeof(iinterface).isassignablefrom(type)) 

note order here. find always use typeof(...) target of call. return true, target has "parent" type , argument has "child" type.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -