-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ElapsedEventArgs doesn't have a public constructor #31204
Comments
To put this in terms of a concrete API proposal: namespace System.Timers
{
public class ElapsedEventArgs : EventArgs
{
+ public ElapsedEventArgs(DateTime signalTime);
}
} |
This seems like a reasonable request. |
At this point it's too late for this to go into 6.0.0. |
Did this make it into 7? It really is a pain |
It has not. Since this issue was originally filed, #44853 changed the constructor to take a @dotnet/area-system-componentmodel this seems like an easy enough one I can take care of if we want to put this through API review. Proposal at #31204 (comment) |
namespace System.Timers;
public sealed class ElapsedEventArgs : EventArgs
{
public ElapsedEventArgs(DateTime signalTime);
} |
I'd be interested to make this change. A quick look at the existing class shows there's already an internal constructor taking a DateTime argument (see below), wouldn't it be sufficient to change this to public (and seal the class)? runtime/src/libraries/System.ComponentModel.TypeConverter/src/System/Timers/ElapsedEventArgs.cs Lines 6 to 14 in 4d2ef11
|
Yep.
We discussed this further in the API review and we didn't think of any reasonable validations that should be applied as the input. |
Changed the internal ElapsedEventArgs constructor to be public, sealed the class, and renamed constructor argument to match property name. Fix dotnet#31204
* ElapsedEventArgs: public constructor + sealed Changed the internal ElapsedEventArgs constructor to be public, sealed the class, and renamed constructor argument to match property name. Fix #31204 * ElapsedEventArgs: added missing XML comment --------- Co-authored-by: Max Klaversma <max.klaversma@vandoren.nl>
System.Timers.ElapsedEventArgs doesn't have a public constructor, despite just being a data class containing one property. This makes it unnecessarily awkward to write a mock for something that uses an ElapsedEventHandler, because you need to use a workaround just to create this one object.
It's impossible to solve this by subclassing ElapsedEventArgs, because the SignalTime property is read-only and therefore cannot be set by your constructor.
The text was updated successfully, but these errors were encountered: