Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to distinguish between interfaces and concrete class?!

Status
Not open for further replies.

tramimaus

IS-IT--Management
Sep 23, 2004
15
US
Does anybody know another way to distinguish between interfaces and concrete class (other than naming conventions)?
For example, suppose someone disregarded the naming conventions but drew the inheritance hierarchy, how could you identify the coclass and the interfaces?!

Does anybody know?

thanks,

-Tramimaus
 
Here is how to do that programmatically:
The Object is the top level class. There is no base type for Object class.
Interfaces inherits also from Object and from 0 or more base interfaces.
The base type of any interface is Object.
To find all the interfaces implemented on the current class and its base classes use TypeTypeDelegator.GetInterfaces().
For a coclass use CoClassAttribute.CoClass() method to return the Type object of the original coclass.
// Assume the current object has a coclass attribute or it was generated by the TlbImp.exe tool when importing a type library.
Code:
Type type = this.GetType();
CoClassAttribute [] attrArray = (CoClassAttribute []) type.GetCustomAttributes(typeof(CoClassAttribute), false);
Type tp = attrArray[0].CoClass();
Type[] arrInterfaces = tp.GetInterfaces() - to get all interfaces
Type tpBase = tp.BaseType()   - to get the base type
All types (class and interface) with their methods (method info) and nested types can be inspected by iterating on the hierarchy until the base type is Object.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top