The error is pretty self evident:
Declare the second parameter of 'EventHandler' as an EventArgs, or an instance of a type that extends EventArgs, named 'e'.
In my example above TMessageType was not inheriting from EventArgs, and thus the warning.
题
Why is this declaration of an event in the following interface complaining in the code analyzer with a CA1009? In the implementation it does indeed seem to follow the standard conventions of event declaration.
using System;
namespace Client.Wpf.Utilities.MessageSubscription
{
public interface ITrigger<TMessageType>
{
event EventHandler<TMessageType> Fire;
}
}
CA1009 Declare event handlers correctly
Declare the second parameter of 'EventHandler' as an EventArgs, or an instance of a type that extends EventArgs, named 'e'.
ITrigger.cs 7
And the implementation:
using System;
//using GalaSoft.MvvmLight.Messaging;
namespace Client.Wpf.Utilities.MessageSubscription
{
public class MvvmMessageTrigger<TMessageType> : ITrigger<TMessageType>
{
public MvvmMessageTrigger()
{
//Messenger.Default.Register<TMessageType>(this, InvokeSubscribers);
}
public event EventHandler<TMessageType> Fire;
private void InvokeSubscribers(TMessageType messageType)
{
if (null != Fire)
{
Fire(this, messageType);
}
}
}
}
解决方案
The error is pretty self evident:
Declare the second parameter of 'EventHandler' as an EventArgs, or an instance of a type that extends EventArgs, named 'e'.
In my example above TMessageType was not inheriting from EventArgs, and thus the warning.