Why do events commonly use EventHandler, even when no arguments need to be
passed?
It is common practice in C# when creating an event, to define it as
follows, taken from an example in the .NET Framework Guidelines:
public class CustomEventArgs : EventArgs
{
public CustomEventArgs(string s)
{
msg = s;
}
private string msg;
public string Message
{
get { return msg; }
}
}
...
public delegate void CustomEventHandler(object sender, CustomEventArgs a);
Often, I create events which don't need any arguments at all. I usually
implement this simply using Action for the event handler type.
public event Action LogonScreenExited;
I was wondering whether there is any reason why one would want to follow
the 'traditional' pattern. Perhaps events like this indicate a design
flaw? My reasoning however for using Action is YAGNI, why implement
something (and even show intent of) when it isn't used?
No comments:
Post a Comment