Skip to content
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

Fix S3264: FP when using add/remove syntax #1219

Closed
Evangelink opened this issue Mar 8, 2018 · 0 comments
Closed

Fix S3264: FP when using add/remove syntax #1219

Evangelink opened this issue Mar 8, 2018 · 0 comments
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@Evangelink
Copy link
Contributor

Description

Rule raises FP when using the add/remove syntax of an event.

Repro steps

public class Foo
{
    private EventHandler someEvent;
    public event EventHandler SomeEvent // Noncompliant - should be compliant
    {
        add
        {
            someEvent += value;
        }
        remove
        {
            someEvent -= value;
        }
    }

    public DoRaise()
    {
        someEvent?.Invoke(this, EventArgs.Empty);
    }
}

Expected behavior

Issue not raised because the event is raised using the private handler.

Actual behavior

Issue is raised because we don't use the event Invoke whereas it is impossible to do so.

Known workarounds

None.

Related information

  • SonarC# Version 7.0
  • Visual Studio Version 2015/2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants