All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S3906.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

Delegate event handlers (i.e. delegates used as type of an event) should have a very specific signature:

  • Return type void.
  • First argument of type System.Object and named 'sender'.
  • Second argument of type System.EventArgs (or any derived type) and is named 'e'.

This rule raises an issue whenever a delegate declaration doesn’t match that signature.

Noncompliant code example

public delegate void AlarmEventHandler(object s);

public class Foo
{
    public event AlarmEventHandler AlarmEvent; // Noncompliant
}

Compliant solution

public delegate void AlarmEventHandler(object sender, AlarmEventArgs e);

public class Foo
{
    public event AlarmEventHandler AlarmEvent; // Compliant
}

Resources

Handling and Raising Events





© 2015 - 2024 Weber Informatics LLC | Privacy Policy