BC30686:默认属性访问在接口“<interfacename1>”的继承接口成员“<defaultpropertyname>”和接口“<interfacename2>”的“<defaultpropertyname>”之间不明确

接口继承自两个接口,每个接口声明同名的默认属性。 未经限定,编译器无法解析对此默认属性的访问。 下面的示例对此进行了演示。

Public Interface Iface1
    Default Property prop(ByVal arg As Integer) As Integer
End Interface
Public Interface Iface2
    Default Property prop(ByVal arg As Integer) As Integer
End Interface
Public Interface Iface3
    Inherits Iface1, Iface2
End Interface
Public Class testClass
    Public Sub accessDefaultProperty()
        Dim testObj As Iface3
        Dim testInt As Integer = testObj(1)
    End Sub
End Class

指定 testObj(1) 时,编译器会尝试解析为默认属性。 但是,由于继承的接口,有两个可能的默认属性,因此编译器会发出此错误的信号。

错误 ID: BC30686

更正此错误

  • 避免继承任何同名的成员。 在上一示例中,如果 testObj 不需要 Iface2 的任何成员(例如),则按如下所示声明它:

    Dim testObj As Iface1
    

    -或-

  • 在类中实现继承接口。 然后,可以使用不同的名称实现每个继承的属性。 但是,其中只有一个可以是实现类的默认属性。 下面的示例对此进行了演示。

    Public Class useIface3
        Implements Iface3
        Default Public Property prop1(ByVal arg As Integer) As Integer Implements Iface1.prop
            ' Insert code to define Get and Set procedures for prop1.
        End Property
        Public Property prop2(ByVal arg As Integer) As Integer Implements Iface2.prop
            ' Insert code to define Get and Set procedures for prop2.
        End Property
    End Class
    

另请参阅