How should I fix SonarLint Rule S1172 "Unused method parameters should be removed" when I create EventHandler methods.
public void Subscribe()
{
MyEvent += OnMyEvent;
}
public void UnSubscribe()
{
MyEvent -= OnMyEvent;
}
private void OnMyEvent(object sender, EventArgs e)
{
DoSomething();
}
You could rewrite the code with Reactive Extensions and making 'Observables' but that is quite complex solution for simple event handlers. Another option could be to rewrite the code like:
public void Subscribe()
{
MyEvent += (s,e) => DoSomething();
}
But the question then is how do you do the UnSubscribe()
? By my opinion the unused parameters is not applicable to event handler methods. But it might be difficult to make detection for that in SonarLint.