Overriding Clear() for a Collection Class 
Author Message
 Overriding Clear() for a Collection Class

I have a collection class as follows:

----Begin Code----
Public Class CustomerCollection

    Inherits System.Collections.CollectionBase

    Private _emailHashtable As New Hashtable()

    Public Sub Add(ByVal newCustomer As Customer)
        Me.List.Add(newCustomer)

        ' add to the hashtable...
        Dim useEmail As String
        useEmail = newCustomer.Email.ToLower
        EmailHashtable.Add(useEmail, newCustomer)
    End Sub

    Public Sub Remove(ByVal removeCustomer As Customer)
         Me.List.Remove(removeCustomer)

         ' remove from the hashtable...
         Dim useEmail As String
          useEmail = removeCustomer.Email.ToLower()
         EmailHashtable.Remove(useEmail)
    End Sub

    Public Overrides Sub Clear()
         MyBase.Clear()
         EmailHashtable.Clear()
    End Sub

    Public Overrides Sub RemoveAt(ByVal index As Integer)
         Remove(Item(index))
    End Sub

    Default Public Property Item(ByVal index As Integer) As Customer
         Get
             Return Me.List.Item(index)
         End Get

         Set(ByVal Value As Customer)
             Me.List.Item(index) = Value
         End Set
    End Property

    Public ReadOnly Property EmailHashtable() As Hashtable
         Get
             Return _emailHashtable
         End Get
    End Property

    Default Public ReadOnly Property Item(ByVal email As String) As Customer
         Get
             email = email.ToLower()
             Return EmailHashtable.Item(email)
         End Get
    End Property

End Class
----End Code----

When I run the app, I get the following error message:
----Begin Message----
An unhandled exception of type 'System.TypeLoadException' occurred in
StructureDemo.exe

Additional information: Declaration referenced in a method implementation
can not be a final method. Type: StructureDemo.CustomerCollection.
Assembly: Clear.
----End Message----

Any ideas why I'm getting this and what I can do to fix it?

Thanks,
Bob



Thu, 13 Jan 2005 22:07:35 GMT  
 Overriding Clear() for a Collection Class
I have a MenuItem and I want to check if it's parent is also a MenuItem.
How should I do that?

TIA

Yves



Quote:
> I have a collection class as follows:

> ----Begin Code----
> Public Class CustomerCollection

>     Inherits System.Collections.CollectionBase

>     Private _emailHashtable As New Hashtable()

>     Public Sub Add(ByVal newCustomer As Customer)
>         Me.List.Add(newCustomer)

>         ' add to the hashtable...
>         Dim useEmail As String
>         useEmail = newCustomer.Email.ToLower
>         EmailHashtable.Add(useEmail, newCustomer)
>     End Sub

>     Public Sub Remove(ByVal removeCustomer As Customer)
>          Me.List.Remove(removeCustomer)

>          ' remove from the hashtable...
>          Dim useEmail As String
>           useEmail = removeCustomer.Email.ToLower()
>          EmailHashtable.Remove(useEmail)
>     End Sub

>     Public Overrides Sub Clear()
>          MyBase.Clear()
>          EmailHashtable.Clear()
>     End Sub

>     Public Overrides Sub RemoveAt(ByVal index As Integer)
>          Remove(Item(index))
>     End Sub

>     Default Public Property Item(ByVal index As Integer) As Customer
>          Get
>              Return Me.List.Item(index)
>          End Get

>          Set(ByVal Value As Customer)
>              Me.List.Item(index) = Value
>          End Set
>     End Property

>     Public ReadOnly Property EmailHashtable() As Hashtable
>          Get
>              Return _emailHashtable
>          End Get
>     End Property

>     Default Public ReadOnly Property Item(ByVal email As String) As
Customer
>          Get
>              email = email.ToLower()
>              Return EmailHashtable.Item(email)
>          End Get
>     End Property

> End Class
> ----End Code----

> When I run the app, I get the following error message:
> ----Begin Message----
> An unhandled exception of type 'System.TypeLoadException' occurred in
> StructureDemo.exe

> Additional information: Declaration referenced in a method implementation
> can not be a final method. Type: StructureDemo.CustomerCollection.
> Assembly: Clear.
> ----End Message----

> Any ideas why I'm getting this and what I can do to fix it?

> Thanks,
> Bob



Thu, 13 Jan 2005 22:08:54 GMT  
 Overriding Clear() for a Collection Class
Never mind ... I closed and reopened the IDE and now it works!  When in
doubt - restart!!!

Bob

Quote:
> I have a collection class as follows:

> ----Begin Code----
> Public Class CustomerCollection

>     Inherits System.Collections.CollectionBase

>     Private _emailHashtable As New Hashtable()

>     Public Sub Add(ByVal newCustomer As Customer)
>         Me.List.Add(newCustomer)

>         ' add to the hashtable...
>         Dim useEmail As String
>         useEmail = newCustomer.Email.ToLower
>         EmailHashtable.Add(useEmail, newCustomer)
>     End Sub

>     Public Sub Remove(ByVal removeCustomer As Customer)
>          Me.List.Remove(removeCustomer)

>          ' remove from the hashtable...
>          Dim useEmail As String
>           useEmail = removeCustomer.Email.ToLower()
>          EmailHashtable.Remove(useEmail)
>     End Sub

>     Public Overrides Sub Clear()
>          MyBase.Clear()
>          EmailHashtable.Clear()
>     End Sub

>     Public Overrides Sub RemoveAt(ByVal index As Integer)
>          Remove(Item(index))
>     End Sub

>     Default Public Property Item(ByVal index As Integer) As Customer
>          Get
>              Return Me.List.Item(index)
>          End Get

>          Set(ByVal Value As Customer)
>              Me.List.Item(index) = Value
>          End Set
>     End Property

>     Public ReadOnly Property EmailHashtable() As Hashtable
>          Get
>              Return _emailHashtable
>          End Get
>     End Property

>     Default Public ReadOnly Property Item(ByVal email As String) As
Customer
>          Get
>              email = email.ToLower()
>              Return EmailHashtable.Item(email)
>          End Get
>     End Property

> End Class
> ----End Code----

> When I run the app, I get the following error message:
> ----Begin Message----
> An unhandled exception of type 'System.TypeLoadException' occurred in
> StructureDemo.exe

> Additional information: Declaration referenced in a method implementation
> can not be a final method. Type: StructureDemo.CustomerCollection.
> Assembly: Clear.
> ----End Message----

> Any ideas why I'm getting this and what I can do to fix it?

> Thanks,
> Bob



Thu, 13 Jan 2005 22:25:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Collection of Collections of Classes

2. VB4 class collections with collections

3. Exposing Properties collection in custom classes as many MS Classes do

4. StatusBarPanel Collection containing panels based on different classes derived from StatusBarPanel class

5. Exposing a Properties collection in custom classes as many MS Classes do

6. Raising events from a class within a collection class

7. Class as collection of another class

8. Looking for 3rd Party Class Library (Collection Class) for Visual Basic

9. Looking for 3rd Party Class Library (Collection Class) for Visual Basic

10. Run an overrides function from base class

11. Object Class Overrides Finalize???

12. Unable to override the Uninstall method in the Installer Class

 

 
Powered by phpBB® Forum Software