---
title: "Implementing CollectionBase the right way"
url: "https://osherove.com/blog/2004/9/7/implementing-collectionbase-the-right-way.md"
canonical: "https://osherove.com/blog/2004/9/7/implementing-collectionbase-the-right-way.html"
published: "2004-09-07T18:27:00"
updated: "2004-09-07T18:27:00"
tags: [".Net Quotations"]
author: "Roy Osherove"
description: "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…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Implementing CollectionBase the right way

By Roy Osherove September 7, 2004 In [.Net Quotations](https://osherove.com/blog/category/net-quotations)

**Historical article** · Originally published September 7, 2004; technical details may be outdated.

[Matt Berther](http://www.mattberther.com/) (The "other" ISerializable...) writes a nice little tidbit about [correctly deriving from CollectionBase](http://www.mattberther.com/2004/09/000540.html) 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.

## More in .Net Quotations

[All posts in .Net Quotations](https://osherove.com/blog/category/net-quotations)

- Sep 13, 2004

    ### [Formatting Hebrew dates](https://osherove.com/blog/2004/9/13/formatting-hebrew-dates.html)

- Sep 11, 2004

    ### [Organization Patterns of Agile Software Development](https://osherove.com/blog/2004/9/11/organization-patterns-of-agile-software-development.html)

- Sep 3, 2004

    ### [Adding pre and post build events for VB.Net projects](https://osherove.com/blog/2004/9/3/adding-pre-and-post-build-events-for-vbnet-projects.html)

- Sep 3, 2004

    ### [Services without components on a pre-SP2 XP machine?](https://osherove.com/blog/2004/9/3/services-without-components-on-a-pre-sp2-xp-machine.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
