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
Post a Comment