I am looking for a native, or a custom-type that covers the following requirements:
- A Generic collection that contains only unique objects like a
HashSet<T> - It implements
INotifyCollectionChanged - It implements
IENumerable<T>(duh) and must be wrappable by aReadOnlyCollection<T>(duh, duh) - It should work with both small and large numbers of items (perhaps changing inner behaviour?)
- the signature of the type must be like
UniqueList<T>(like a list, not a key/valuepair) - It does not have to be sortable.
- Searchability is not a “must-have”.
The main purpose of this is to set up a small mesh/network between related objects.
So this network can only unique objects and there has to be a mechanism that notifies the application when changes in the collection happen.Since it is for a proof-of-concept the scope is purely within the assembly (no db’s or fs are of any importance).
What is a proper native type for this or what are the best ingredients to create a composite?
Sounds like you could just wrap
HashSet<T>in your own type extremely easily, just to implementINotifyCollectionChanged. You can easily proxy everything you need – e.g.GetEnumeratorcan just callset.GetEnumerator()etc. ImplementingINotifyCollectionChangedshould just be a matter of raising the event when an element is added or removed. You probably want to make sure you don’t raise the event if either you add an element which is already present or remove an element which isn’t already present.HashSet<T>.Add/Removeboth returnboolto help you with this though.I wouldn’t call it
UniqueList<T>though, as that suggests list-like behaviour such as maintaining ordering. I’d call itObservableSet<T>or something like that.