Is it possible to run code aftter or before the item was added to collection?
Lets say i have object Product with property Price and Warehouse object with properties IList Products and TotalPrice. I need to update TotalPrice each time the collection was modified. I dont want to calculate TotalPrice inside that property each time its accessed.
If it is possible only with AOP, is there any free AOP framework for .net?
Take a look at
ObservableCollection<T>, which is a collection designed especially for the scenario you described:MSDN link: “Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.”