简体   繁体   中英

Is the “object sender” in EventHandler<T> enough or Should I include a reference of the sender in my custom EventArgs?

Question says it all.

Related thought/question:

Is there a way to " bubble-up " events then change the original sender without "intercepting" the event?

Example implementation:

public class Wheel
{
     public EventHandler<WheelTurningEventArgs> Turning;
}

This is the one without the sender in the EventArgs:

public class WheelTurningEventArgs : EventArgs
{
      public int TotalTurnCount { get; set; }
}

... and this is the one with the sender in the EventArgs.

public class WheelTurningEventArgs : EventArgs
{
       public Wheel Wheel {get; set;} //include a reference to the wheel that invoked this event
       public int TotalTurnCount { get; set; }

}

如果这是路由事件,则WheelTurningEventArgs应该从RoutedEventArgs类继承,该类将具有原始来源以及发送者。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM