Hi!
I'm using NHibernate in my project. I wanted to create collections for my classes because there are many calculated properties and I need to be able to sort collections by these properties.
So, I created my own base collection that has reference to IList that I get from NHibernate. This base class implements all needed interfaces for databinding. Then I wrote custom object comparer to easily sort my collections using reflection. All common collection functionality is implemented in base class. Each collection has just constructor that calls base class constructor and indexer property that returns object with correct type.
When my manager class needs to return some of my collection it makes query, creates collection with correct type and gives IList to this collection's constructor. Now constructor tries to cast it to ArrayList. It succeeds when I get IList by using IQuery or ICriteria. It doesn't succeed if I want to return some object's property as my collection (mapped as bag etc). In this case my base class creates new ArrayList and copies all objects from IList to ArrayList as IList interface is still implemented.
I want to ask if there is any better way to manage custom collections? What can be side effects of my solution? My goal is to have library that applications can use without knowing a thing about NHibernate and database.
With best regards,
Gunnar Peipman
|