2

Is there something like this already available in the .NET framework?

public class EventArgs<T> : EventArgs {
    private readonly T data;

    public EventArgs(T data) {
        this.data = data;
    }
}

I know there is a generic event handler, I'm kinda surprised I can't find a generic EventArgs class.

Thanks

devoured elysium
  • 101,373
  • 131
  • 340
  • 557
  • Honestly, I have no idea why the regular EventArgs even exists. It adds no functionality to the system (and holds no data and exposes no behavior). Therefore a "generic equivalent" doesn't really even make sense. – Kirk Woll Aug 14 '10 at 13:17
  • It does exist in some assemblies/namespaces. http://stackoverflow.com/questions/3312134/does-net-have-a-built-in-eventargst/15896769#15896769 – Ulf Åkerstedt Apr 09 '13 at 09:11
  • See also this relevant answer: http://stackoverflow.com/a/129613/1298001 – Ulf Åkerstedt Apr 09 '13 at 09:14

1 Answers1

8

No. Mainly because it fails the tests posed before something it added to the framework

  • How useful is it? (Marginly -- only useful if you only need one data member. As opposed to EventHandler<> which is good for event handler regardless of the number of parameters used.)
  • How hard is it to write yourself? (not very hard)
  • Is it needed in the framework itself? (No. Distinct classes are used, so new members could be added in the future if needed. As opposed to Func<> & Action<> which are used by the framework.)

(UPDATED based on comments)

James Curran
  • 101,701
  • 37
  • 181
  • 258
  • It's certainly as useful as having a EventHandler. Yet, that one exists. – devoured elysium Aug 14 '10 at 13:18
  • +1 - I have to agree with this, inheriting and adding the properties you need seems much more useful in most cases. – Nick Craver Aug 14 '10 at 13:19
  • You could have something like EventArgs, EventArgs, EventArgs, etc. It'd certainly ease up things and wouldn't give them any trouble doing so. It's like saying there is really no point in having all those Action<...> and Func<...>. – devoured elysium Aug 14 '10 at 13:20
  • @devoured - `Func` is supported in the language's syntax, and is widely useful. `EventArgs` will just let you create event arguments with properties **without meaningful names** (like a Tuple) - something that you probably want to avoid. – Kobi Aug 14 '10 at 13:24