I’ve been pondering if/how to implement an Observable Collection type class in the MicroLinq project for NETMF. Tonight I finally set about doing it.
I started with the ValueTypeArrayList class, removed the type restriction and switched storage to just plain old object. I took a look at the current ObservableCollection in the full framework and set about deciding what was a must-have and what could be tossed away to save memory and footprint.
It was obvious the CollectionChanged event was necessary but I threw away the PropertyChanged event. It just didn’t seem to provide anything useful in this case. So, concentrating just on the CollectionChanged event, I looked at the EventArgs and saw a lot of code which basically provides a read-only copy of the old and/or new collection (before the modification and after) depending on the change type. I cut this first because I just couldn’t justify the memory usage.
That left only the Action type of which there are 5 in the full framework. Only 3 could ever be reported from my implementation so I cut the other two leaving just Add, Remove and Reset. I kept the class and interface names the same as the full framework in case there’s ever a native implementation. It should be trivial to port code that makes use of NotifyingCollection now this way.