Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the EventArgs constructor not protected?

I'm wondering why the EventArgs constructor isn't protected as it seems like waste (although tiny) to allocate resources for an empty object for every event, especially when there is a singleton EventArgs.Empty that's clearly more efficient to use. This surprises me, especially when other parts of the .NET do have a protected/private constructor to avoid multiple, unnecessary allocations, e.g. Comparer<T>.

Are there any cases where creating a new EventArgs() (not a subclass) actually makes sense, or is the constructor merely available to ease the usage for non-experienced developers?

like image 424
larsmoa Avatar asked May 27 '11 08:05

larsmoa


1 Answers

I would say that its because the EventArgs class has the ComVisible attribute set to true.

This is supported by the following FxCop rule:

A reference type that is specifically marked as visible to COM contains a public parameterized constructor but does not contain a public default (parameterless) constructor.

like image 171
João Angelo Avatar answered Nov 16 '22 02:11

João Angelo