0

我创建了一个继承自的类,BindingList(of T)并添加了一个 Item(indx as Integer)隐藏基本属性项的属性,如下所示

<System.Reflection.DefaultMember("Item")> _
Public Class Unity(Of T As {New, Entity})
    Inherits BindingList(Of T)
    Implements IUnity

    Public Property Item(ByVal indx As Integer) As T
        Get
            If indx >= Me.Count Then
                Throw New ArgumentOutOfRangeException("index")
            End If
            If Not MyBase.Item(indx)._IsLoaded Then InitDataOfItemsInPage(indx)
            Return MyBase.Item(indx)
        End Get
        Set(ByVal value As T)
            MyBase.Item(indx) = value
        End Set
    End Property

    ......
End Class

现在,当我尝试访问一个项目时,myUnity.Item(1)一切都可以正常工作。代码转到属性 Item 执行它必须执行的操作并返回 myEntity。但是如果我写myUnity(1)我得到 myEntity 而不通过属性 item 有人知道为什么吗?

4

1 回答 1

0

看起来 BindingList(of T) 中的“默认属性项”优先于 Unity(...) 类中的 DefaultMemberAttribute。我不知道为什么。

Default Property Item(ByVal indx As Integer) As T 而不是 <DefaultMember>(...) 工作正常。

于 2011-04-05T19:48:28.983 回答