且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C#中标记有ComVisible特性的类接口继承

更新时间:2023-09-24 18:23:04

我偷了这个问题的答案从的 COM互操作:基本类的属性不会暴露给出COM 链接非常类似的问题C#暴露在COM - 接口继承

I'm stealing the answer to this from the COM Interop: Base class properties not exposed to COM link given in the very similar question "C# exposing to COM - interface inheritance"

在特别在该网站上的MVP指出:

In particular the MVP on that site states:

在COM接口可以相互继承。然而,公开的.NET接口,COM的.NET实现不支持继承。因此,你必须复制在基本界面任何接口成员派生的接口......建立暴露COM接口时,互操作的代码不看基本接口类型。

In COM interfaces can inherit from one another. However the .NET implementation that exposes the .NET interface to COM does not support inheritance. Therefore you must replicate any interface members in a base interface to the derived interface... The interop code does not look at base interface types when building the exposed COM interface.

它确实提出了一些解决方法,比如从两个接口继承,或实施一个'本土'的TLB(写inteface在IDL和MIDL编译 - 应该有这可见工作室项目)

It does suggest some workarounds, such as inheriting from both interfaces, or implementing a 'native' TLB (write the inteface in IDL and compile it with MIDL - there should be projects for this in vis studio).