为什么 myList(i) 不通过 BindingList(of T) 继承类中的属性 Item 传递
我创建了一个继承自 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 而不通过属性项 有谁知道为什么?
I have create a class that inherits from BindingList(of T)
and I added a propertyItem(indx as Integer)
that shadows base property item as it follows
<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
Now when i try to acces an item writing myUnity.Item(1)
everythings works fine.
The code goes to the property Item does what it has to do and returns the myEntity.
But if I write myUnity(1)
I get myEntity without passing through the property item
Does anyone knows why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 BindingList(of T) 中的“默认属性项”优先于 Unity(...) 类中的 DefaultMemberAttribute。我不知道为什么。
默认属性项(ByVal indx As Integer) As T
而不是
<默认成员>(...)
工作正常。
It looks like "default property item" from BindingList(of T) takes precedence before DefaultMemberAttribute in Unity(...) class. I don't know why.
Default Property Item(ByVal indx As Integer) As T
instead of
<DefaultMember>(...)
works fine.