G
Guest
I have this:
Public Class clsItem
Implements IComparer
Public Name As String
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements IComparer.Compare
Dim empx As clsItem = DirectCast(x, clsItem)
Dim empy As clsItem = DirectCast(y, clsItem)
Return String.Compare(empx.Name, empy.Name)
End Function
End Class
<Serializable()> Public Class clsCategory
Inherits clsItem
Public SubOf As String
End Class
Public Class CategoryCollection
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal index As Integer) As
clsCategory
Get
Return CType(List(index), clsCategory)
End Get
End Property
Public Function Add(ByVal item As clsCategory) As Integer
Return List.Add(item)
End Function
Public Sub Insert(ByVal index As Integer, ByVal item As clsCategory)
List.Insert(index, item)
End Sub
Public Sub Remove(ByVal item As clsCategory)
List.Remove(item)
End Sub
Public Function IndexOf(ByVal item As clsCategory) As Integer
Return List.IndexOf(item)
End Function
Public Sub Sort()
InnerList.Sort(Me)
End Sub
End Class
<Serializable()> Public Class clsFile
Inherits clsItem
Public Category As String
Public FileName As String
Public Description As String
End Class
Public Class FileCollection
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal index As Integer) As clsFile
Get
Return CType(List(index), clsFile)
End Get
End Property
Public Function Add(ByVal item As clsFile) As Integer
Return List.Add(item)
End Function
Public Sub Insert(ByVal index As Integer, ByVal item As clsFile)
List.Insert(index, item)
End Sub
Public Sub Remove(ByVal item As clsFile)
List.Remove(item)
End Sub
Public Function IndexOf(ByVal item As clsFile) As Integer
Return List.IndexOf(item)
End Function
Public Sub Sort()
InnerList.Sort(Me)
End Sub
End Class
Now isn't there some way that I can create just an ItemCollection instead of
having to create a CategoryCollection, a FileCollection, and so on for every
new class I create?
Public Class clsItem
Implements IComparer
Public Name As String
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements IComparer.Compare
Dim empx As clsItem = DirectCast(x, clsItem)
Dim empy As clsItem = DirectCast(y, clsItem)
Return String.Compare(empx.Name, empy.Name)
End Function
End Class
<Serializable()> Public Class clsCategory
Inherits clsItem
Public SubOf As String
End Class
Public Class CategoryCollection
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal index As Integer) As
clsCategory
Get
Return CType(List(index), clsCategory)
End Get
End Property
Public Function Add(ByVal item As clsCategory) As Integer
Return List.Add(item)
End Function
Public Sub Insert(ByVal index As Integer, ByVal item As clsCategory)
List.Insert(index, item)
End Sub
Public Sub Remove(ByVal item As clsCategory)
List.Remove(item)
End Sub
Public Function IndexOf(ByVal item As clsCategory) As Integer
Return List.IndexOf(item)
End Function
Public Sub Sort()
InnerList.Sort(Me)
End Sub
End Class
<Serializable()> Public Class clsFile
Inherits clsItem
Public Category As String
Public FileName As String
Public Description As String
End Class
Public Class FileCollection
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal index As Integer) As clsFile
Get
Return CType(List(index), clsFile)
End Get
End Property
Public Function Add(ByVal item As clsFile) As Integer
Return List.Add(item)
End Function
Public Sub Insert(ByVal index As Integer, ByVal item As clsFile)
List.Insert(index, item)
End Sub
Public Sub Remove(ByVal item As clsFile)
List.Remove(item)
End Sub
Public Function IndexOf(ByVal item As clsFile) As Integer
Return List.IndexOf(item)
End Function
Public Sub Sort()
InnerList.Sort(Me)
End Sub
End Class
Now isn't there some way that I can create just an ItemCollection instead of
having to create a CategoryCollection, a FileCollection, and so on for every
new class I create?