接口未声明的类的访问属性

时间:2015-03-31 01:14:22

标签: vb.net class interface

如何访问未在其实现的接口中声明的类的属性?

Interface IMyInterface

    Property MyInterfaceProperty As String

End Interface

Public Class MyImplementingClass
    Implements IMyInterface

    Public Property MyClassProperty As String

    Public Property MyInterfaceProperty As String Implements IMyInterface.MyInterfaceProperty
End Class

Public Class MyTestClass

    Public Sub New()
        Dim foo As IMyInterface = New MyImplementingClass
        foo.MyInterfaceProperty = "foo"
        foo.MyClassProperty = "bar" '### Compile Error MyClassProperty is not a member of IMyInterface
    End Sub

End Class

我已尝试添加

foo = CType(foo, MyImplementingClass)

但它不起作用......

0 个答案:

没有答案