IMHO, everything's fine unless it's a keyed collection of elements. Here's an example:
1) There's an Attribute type, having Name property (String). Two Attributes are considered equal if their Names are equal.
2) There's also a generic keyed collection of Attribute elements named Attributes:
<Serializable()> _
Public Class Attributes
Inherits KeyedCollection(Of String, Attribute)
Sub New()
MyBase.New()
End Sub
Protected Overrides Function GetKeyForItem(ByVal item As Attribute) As String
Return item.Name
End Function
...
Then, here's how you access collection elements (by name):
Dim myAttributes As New Attributes()
... fill the collection ...
Dim myAttribute As Attribute = myAttributes("KeyName")
Both Attribute and Attributes types need to be decorated with Serializable() attribute. That's it. You don't need to bother with property/method serialization attributes since only Public ones will get serialized/deserialized.
Regards,
Maksim Sestic