Is it smelly to raise an event from within another event?
c#, events
Solution
While I have seen it, I would recommend against it and raise the event in methods that it would occur in, like your `UnitCount` setter. Since you have the `virtual` access modifier keyword, someone could override the method and if they don't call the base object it wouldn't work as expected.
I'm not a fan of making it more complicated to use my code.
Problem
``` public class Basket { private int _unitCount; public int UnitCount { get { return _unitCount; } set { _unitCount = Math.Max(0, value); OnUnitCountChanged(new EventArgs()); } } public event EventHandler UnitCountChanged; public event EventHandler Depleted; protected virtual void OnUnitCountChanged(EventArgs args) { var handler = UnitCountChanged; if(handler!=null) { handler(this, args); } if(_unitCount == 0) { OnDepleted(new EventArgs()); } } protected virtual void OnDepleted(EventArgs args) { var handler = UnitCountChanged; if(handler!=null) { handler(this, args); } } } ``` Is there a problem with checking the conditions for Depleted and raising that event if necessary within the UnitCountChanged event, or should I be doing both in the UnitCount setter (and anywhere else in a non-trivial example)?