« What do you use for blog publishing software on Windows? | Main | Google RSS Reader »

.NET 2.0 Dictionary Annoyance ...

Arrgh! I want to create an “observable” Dictionary class. Anytime an item is added, removed, etc., I want an event to be raised.

Using the System.Collections.Generic.Dictionary<TKey, TValue> class however is a no-go. Microsoft did not provide virtual methods for the dictionary modification methods (like Add). Dictionary happens to be one of those classes that isn’t a quick aggregation away from making a new version either, it has complex serialization, implements a bunch of interfaces, etc. Very annoying. I would have been less annoyed (in a way) had they done the same for the Collection<T> class. It however has all of the needed virtual methods to make it possible to observe. (OK, so that’s actually a positive thing, but it’s inconsistent).

I could use the C# new modifier, but then it doesn’t give me the true OOP behavior I need as there would be still methods of getting access to the dictionary without going through my methods by simple type-casting.

If I’m missing something, please help! Otherwise, score one less for the .NET 2.0 Framework.

Comments

Have you tried ObservableCollection ?

Only exists in Avalon/WPF framework. It's not in .NET 2.0

Help support my web site by searching and buying through Amazon.com (in assocation with Amazon.com).