Generic EventArgs implementation (but isn't really all that useful)
/public class EventArgs<T> : EventArgs
{
private T t;
public EventArgs(T t)
{
this.t = t;
}
public T Value
{
get { return t; }
set { t = value; }
}
}
To use this class:
public EventHandler<EventArgs<String>> Notification;
protected void OnNotification(string message)
{
var handler = Notification;
if (handler != null)
{
handler(this, new EventArgs<String>(message));
}
}
While this code is all nice and dandy, I wonder if it's all that useful. One of the things with custom event args is that they may grow over time, and this implementation doesn't support future scenarios that well.
My colleague Dinesh mentioned that perhaps I'll end up going down the Func<> route, ie:
EventArgs<T>, EventArgs<T, U>, EventArgs<T, U, V>
Personally I think that's a bit challenging:
If I had to add an future int property to my EventArgs<String>, changing the event to EventArgs<String, int> doesn't automatically fix the issue - as all my event hooks will now stop compiling, because EventArgs<String, int> doesn't imply it inherits from EventArgs<String>
Anyway, nice looking bit of code but I'd say not greatly useful.