Author Topic: serialize collectionBase  (Read 6614 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Guest
Re: serialize collectionBase
« Reply #15 on: November 28, 2007, 07:48:29 PM »
okay, you got me with that one. I can usually decipher the Australian but..... :)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: serialize collectionBase
« Reply #16 on: November 28, 2007, 07:49:56 PM »
yes, generics ..
thats what I meant by the reference to the last paragraph of the article I referenced to.


Glenn,
those samples look functionally familiar.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: serialize collectionBase
« Reply #17 on: November 28, 2007, 07:51:41 PM »
no flaming worries = nurries.

or

all is cool.

added:
it's actually just 'no worries'
Strine is easy if you hold your nose and run words together.

also added later:
* sometimes reality should not stand in the way of a good story

« Last Edit: November 28, 2007, 08:02:14 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MaksimS

  • Guest
Re: serialize collectionBase
« Reply #18 on: November 29, 2007, 04:13:05 AM »
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:

Code: [Select]
<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):

Code: [Select]
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


Glenn R

  • Guest
Re: serialize collectionBase
« Reply #19 on: November 29, 2007, 04:41:07 AM »
Glenn,
those samples look functionally familiar.

Hehe...I thought you would spot that Kerry.

Glenn R

  • Guest
Re: serialize collectionBase
« Reply #20 on: November 29, 2007, 04:42:39 AM »
it's actually just 'no worries'

also added later:
* sometimes reality should not stand in the way of a good story


Correct on both counts there Kerry and yes you definately shouldn't let reality ruin a good yarn.