Can base/derived classes in C# be exported to COM?

COM Interop is a wonderful technology. One aspect of the common language runtime (CLR) that makes it an extremely powerful platform is that it allows seamless interactions between managed applications and unmanaged COM components.
  • COM only deals with interfaces. Base/derived classes have no meaning or functionality in COM. Inheritance is not applicable either.
  • In COM, interfaces can inherit from one another. However, the .NET implementation that exports the .NET interface to COM does not support inheritance. Therefore, we must replicate any interface members in a base interface to the derived interface.
  • Moving members between a base and derived class will have no impact on what is visible to COM.
  • The programmer can only define what is exposed to COM. The compiler will not use reflection or anything else to determine what should be exposed.
  • All COM classes have a single, default interface. This is the interface that is normally used for an object. A COM class can expose other interfaces but the COM client must then query for the interface. In .NET the first COM visible interface is used as the default interface for a COM class.

No comments:

Post a Comment