-1

I'm looking for a way to check when Pop() function is called on my Stack structure I'm currently using a property with extended setter however .Pop() doesn't seems to trigger the setter and I'm pretty much unable to determine when the collection is actually changed unless I'm changing reference itself. Any tips on this one ? Again I only care about the Pop() function I don't really want to know when Push is invoked or anything else that can modify the collection.

mashinkata
  • 45
  • 1
  • 9
  • 1
    Possible duplicate of [Observable Stack and Queue](http://stackoverflow.com/questions/3127136/observable-stack-and-queue) – Jan-Fokke Nov 18 '16 at 15:52

1 Answers1

0

You'll have to create your own collection (most likely just wrapping a Stack reference) so that you can create an event and trigger it when a given operation (in this case, any collection change by the sounds of it) is performed. Other than your even logic, you can just create a member for each public member of Stack and have it simply forward the call onto a private Stack instance.

Servy
  • 193,745
  • 23
  • 295
  • 406
  • Added a small but important detail 1-2 seconds before you answered that I need only to fire this event on Pop, btw I'm already running with an extended `Stack` collection but I'm not sure how this event can be added. – mashinkata Nov 18 '16 at 14:53
  • If you already have your own `Stack` class then define an event and invoke the event in the `Pop` method. – Servy Nov 18 '16 at 14:54
  • Thank you a lot for the quick answer just to make sure I've done stuff right. I've a class that inherits simply `IEnumerable` so i can enumerate it and the class itself has a `private readonly Stack _stack` collection inside, and also the class has all the `Stack` functions which all look for example like this `public T Peek() { return _stack.Peek(); }` + there is an event which is triggered in `Pop()` is that correct ? – mashinkata Nov 18 '16 at 15:11