|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Advanced OOP QuestionPublic 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? have a look into generics which come with VS2005.
Show quote "Alex C. Barberi" <AlexCBarb***@discussions.microsoft.com> schrieb im Newsbeitrag news:A7E54BC4-904E-492E-B52A-14B571B4CAC5@microsoft.com... >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? > > -- > Alex C. Barberi > Chief Executive Officer > VisionForce > http://www.visionforceweb.com > No good. I'm using VS2002.
Show quote "cody" wrote: > have a look into generics which come with VS2005. > > "Alex C. Barberi" <AlexCBarb***@discussions.microsoft.com> schrieb im > Newsbeitrag news:A7E54BC4-904E-492E-B52A-14B571B4CAC5@microsoft.com... > >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? > > > > -- > > Alex C. Barberi > > Chief Executive Officer > > VisionForce > > http://www.visionforceweb.com > > > > > there are programs which are able to generate source code for a strong typed
collection given a template and a type. for example the free IDE sharpdevelop is able to do that. Show quote "Alex C. Barberi" <AlexCBarb***@discussions.microsoft.com> schrieb im Newsbeitrag news:A31B1581-E196-4501-83D1-FBE366BEAFB9@microsoft.com... > No good. I'm using VS2002. > > -- > Alex C. Barberi > Chief Executive Officer > VisionForce > http://www.visionforceweb.com > > > > "cody" wrote: > >> have a look into generics which come with VS2005. >> >> "Alex C. Barberi" <AlexCBarb***@discussions.microsoft.com> schrieb im >> Newsbeitrag news:A7E54BC4-904E-492E-B52A-14B571B4CAC5@microsoft.com... >> >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? >> > >> > -- >> > Alex C. Barberi >> > Chief Executive Officer >> > VisionForce >> > http://www.visionforceweb.com >> > >> >> >> Alex C. Barberi wrote:
> Now isn't there some way that I can create just an ItemCollection instead of Since you said you are pre-VS2005, your best option is a code> having to create a CategoryCollection, a FileCollection, and so on for every > new class I create? generation tool such as CodeSmith (that's actually the only one I know). You will have to write your own templates, most likely, but it's pretty straightforward. -- Larry Lard Replies to group please |
|||||||||||||||||||||||