I've been converting a fairly substantial web site to NHibernate 2.1.2 (from 1.5), and during that conversion process was having some difficulties with a custom collection that had been mapped using the method explained by Billy McCafferty. Upon close inspection I found that only one method actually was doing anything different to a regular list - Add - so I wanted to find a way to do it more simply.

The first thing I thought of was using Extension methods as suggested in Billy's next post, but that doesn't work for existing methods - you can make an extension method but it will never be called if it has the same signature as an existing method. I found another post by Colin Jack which allows you to just use a to map a custom list far more simply. It took about 20 minutes to set up and works perfectly! I find this method to be far cleaner. </p>

I basically just made a base class called OverridableCollection</code> as suggested which implements ICollection</code> with an IList _innerList = new List();</code> and made all of the methods virtual. The custom collection then inherits from this base class and overrides where necessary, and adds any other new functionality that is required. So far so good :)</p>

Changing from a List to a collection meant changing some unit tests that were accessing individual elements by index, but that was all set up code so it was easy enough to do that before actually adding. All in all, I think it's a really good change and will try to use this method in the future.