Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3264

Events should be invoked

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove this unused event or invoke it.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      C#
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • Analysis Scope:
      Main Sources, Test Sources
    • ReSharper:
      EventNeverInvoked

      Description

      Events that are not invoked anywhere are dead code, and there's no good reason to keep them in the source.

      Noncompliant Code Example

      class UninvokedEventSample
      {
          private event Action<object, EventArgs> Happened; //Noncompliant
      
          public void RegisterEventHandler(Action<object, EventArgs> handler)
          {
              Happened += handler; //we register some event handlers
          }
      
          public void RaiseEvent()
          {
              if (Happened != null)
              {
                  // Happened(this, null); // the event is never triggered, because this line is commented out.
              }
          }
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: