Implementing CollectionBase the right way - ISerializable - Roy Osherove's Blog

Implementing CollectionBase the right way

Matt Berther (The "other" ISerializable...) writes a nice little tidbit about correctly deriving from CollectionBase and adds something I was not aware of:
you really really want to override the OnValidate() event of CollectionBase so that you can validate objects before being added to the collection. This is crucial when someone casts your collection to an IList interface and then can have their way with your collection without your approval, unless you override this important method.
Thanks Matt.
Published Wednesday, September 08, 2004 12:27 AM by RoyOsherove
Filed under:

Comments

Tuesday, September 07, 2004 7:12 PM by Alex Campbell

# re: Implementing CollectionBase the right way


Great advice! This had never occured to me and now I'm kicking myself because it seems so obvious.