本文介绍了在C#中标记有ComVisible特性的类接口继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继承财产(P1)是不是从W / CSCRIPT accessable。

Inherited property (P1) is not accessable from w/cscript.

类的结构看起来是这样的:

Class structure looks something like this :

[ComVisible]
public interface IA
{
     string P1{get;}
}

[ComVisible]
public interface IB : IA
{
    string P2{get;}
}

[ComVisible]
public abstract class Base : IA
{
    public string P1{get{return "somestring";}}
}

[ComVisible]
public class Concrete : Base, IB
{
   public string P2{get{return "P2somestring";}}
}

客户端代码:

try{
var obj = new ActiveXObject("Concrete");
WshShell.Popup(obj.P1); //<-- displays empty string
}catch(e)
{
WshShell.Popup(e.description);
}

如果我添加属性P1接口IB,一切工作正常,
,而什么传承然后点?还是我在这里做的东西真的错了?

if i add property P1 to interface IB, everything works fine,but whats the point of inheritance then? Or am i doing here something really wrong?

推荐答案

我偷了这个问题的答案从的链接非常类似的问题

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接口时,互操作的代码不看基本接口类型。

它确实提出了一些解决方法,比如从两个接口继承,或实施一个'本土'的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).

这篇关于在C#中标记有ComVisible特性的类接口继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:16