次の方法で共有


BC30686: 既定のプロパティ アクセスは、インターフェイス '<interfacename1>' の継承されたインターフェイス メンバー '<defaultpropertyname>' とインターフェイス '<interfacename2' の '<defaultpropertyname>' の間であいまいです>

インターフェイスは 2 つのインターフェイスを継承し、それぞれが同じ名前の既定のプロパティを宣言します。 コンパイラは、修飾なしでこの既定のプロパティへのアクセスを解決できません。 次に例を示します。

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)を指定すると、コンパイラはそれを既定のプロパティに解決しようとします。 ただし、継承されたインターフェイスが原因で既定のプロパティが 2 つ考えられるため、コンパイラはこのエラーを通知します。

エラー ID: BC30686

このエラーを解決するには

  • 同じ名前のメンバーは継承しないでください。 前の例では、 testObjIface2 などのメンバーを必要としない場合は、次のように宣言します。

    Dim testObj As Iface1
    

    -又は-

  • 継承インターフェイスをクラスに実装します。 その後、継承された各プロパティを異なる名前で実装できます。 ただし、実装クラスの既定のプロパティにできるのは、そのうちの 1 つだけです。 次に例を示します。

    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
    

こちらも参照ください