Clarification of serialization issues

G

Guest

I was after clarification of some of serialization issues. I think I know
the answers, but I want to be sure.


1. In a serializable collection class is it mandatory (for serialization) to
have a default Item property that is effectively

indexed by the IList index?

Example 1
---------
Default Public ReadOnly Property Item(Index As Integer) As MyObject
Get
Return DirectCast(List.Item(Index), MyObject)
End Get
End Property


2. Is there ever an occasion when this property is not read-only? If so, do
you have an example?

3. It's possible for the Item property to have an alternative version with
another signature:

Example 2
---------

Default Public ReadOnly Property Item(KeyValue As String) As MyObject
Get
Dim objChild as MyObject

For Each objChild in List
If objChild.KeyValue.Equals(KeyValue) Then
Return DirectCast(List.Item(Index), MyObject)
End If
Next

Return Nothing
End Get
End Property

but an integer key value (ie KeyValue As Integer in the above) would have
the same signature as Example 1 which rules it out (unless

someone knows better).

So if it's mandatory to have an Item property indexed by the List index,
what's the best practice for returning an object which is

referenced by the key value - which will be more than likely a Primary Key
integer value from SQL Server?

TIA

Crispin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top