Tracking Changes to Generic Collections

I'm writing an app that makes heavy use of Generic collections, and I'm needing to keep track of objects that are added or deleted. Is there a built-in object that supports this already? I'm about 3/4 of the way finished with my own inherited class that does the trick, but I wanted to throw it out there, in case I'm wasting my time. Thanks guys!

UPDATE: I was up late last night writing some great code that totally does the trick, I'll post it as soon as I'm done commenting it all out.

3 Comments

  • I looked over it, doesn't look like it would work for what I'm looking for. Was there a specific part of that package that you were thinking of?

  • I've needed the same thing. In fact, I'm rolling my own right now. I've never seen anything built in that will work. I've gone two ways in the past. One was raising events when the collection's state changed and the other was holding a reference to an owner object that took the update notifications.

  • Maybe I'm amiss here, but isn't this what System.ComponentModel.BindingList<T> is supposed to do?



    Frans: what do you mean? Collection<T> calls virtual methods RemoveItem and InsertItem for Add/Remove/Inserts. If you override RemoveItem and InsertItem, how can a user still bypass your changetracking (or BindingLists, because that overrides those methods to do the change tracking)? (And I mean in "normal" usage, with Reflection you can do all kinds of nasty things of course)

Comments have been disabled for this content.