公开COM vb.net类的继承成员 [英] Exposing inherited members of a COM vb.net class

查看:136
本文介绍了公开COM vb.net类的继承成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个vb.net类:

I have two vb.net class:

Public MustInherit Class Class1
    Private m_sProperty1 As String = ""
    Public Property sProperty1() As String
        Get
            Return m_sProperty1
        End Get
        Set(ByVal value As String)
            m_sProperty1 = value
        End Set
    End Property
End Class

<ComClass("classid","interfaceid","eventid")> _
Public Class Class2
    Inherits Class1

    Private m_sProperty2 As String = ""
    Public Property sProperty2() As String
        Get
            Return m_sProperty2
        End Get
        Set(ByVal value As String)
            m_sProperty2 = value
        End Set
    End Property
End Class

当我通过VB6引用编译的DLL时,Class2仅公开sProperty2.如何通过COM访问基类(sProperty1)的继承属性?

When I reference the compiled DLL through VB6, Class2 only exposes sProperty2. How can I access the inherited property of the base class (sProperty1) through COM?

推荐答案

这似乎在回答您的问题:

This seems to answer your question:

导出继承层次结构

作为COM对象公开时,托管类层次结构变得平坦.例如,如果您定义一个带有成员的基类,然后在作为COM对象公开的派生类中继承该基类,则在COM对象中使用派生类的客户端将无法使用继承的成员. .只有作为基类的实例才能从COM对象访问基类成员,只有当基类也被创建为COM对象时,才可以访问基类成员.

Managed class hierarchies flatten out when exposed as COM objects. For example, if you define a base class with a member, and then inherit the base class in a derived class that is exposed as a COM object, clients that use the derived class in the COM object will not be able to use the inherited members. Base class members are accessible from COM objects only as instances of a base class, and then only if the base class is also created as a COM object.

来自此处:互操作性问题

这篇关于公开COM vb.net类的继承成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆