Ticket T548911
Visible to All Users

"Empty Event Handler" analyzer should be implemented in CodeRush for Roslyn

created 8 years ago

Not sure if you'd prefer a separate ticket for this, but I did find a problem with events (or rather, event handler).
Visual Studios CodeLens shows 1 reference, but CRR insists that the event handler is unused.

This only happens for empty event handlers and event handlers that throw exceptions (but don't do anything else).

C#
public event EventHandler<EventArgs> EmptyHandler; public event EventHandler<EventArgs> ThrowingHandler; public void Test() { EmptyHandler += OnEmptyHandler; ThrowingHandler += OnThrowingHandler; EmptyHandler?.Invoke(this, EventArgs.Empty); ThrowingHandler?.Invoke(this, EventArgs.Empty); } private void OnEmptyHandler(object sender, EventArgs ea) // CRR0026 { // intentionally left blank } private void OnThrowingHandler(object sender, EventArgs ea) // CRR0026 { throw new NotSupportedException("This should not happen for " + sender.ToString()); }

I can get behind the first one (because doing nothing in the event handler looks strange; and in fact the only place where this happens for me has a big "TODO" next to it), but I'm not too sure about the second one. Doing anything else than just the exception in there (like a Console.WriteLine, a null-check or anything) makes the message disappear.
Use case for the second kind of event handler is a "something happened" event that should log in one place, do nothing in another but abort the action in a third location (which all use the same event raiser, but handle it differently).
It feels as if the second case should specifically check for NotImplementedException on a generated event handler that is yet to be updated with proper code; but instead triggers for any kind of exception being thrown unconditionally.

Comments (1)
DevExpress Support Team 8 years ago

    Hi Emanuel, We agree these are incorrect diagnostic notifications in both cases. We decided to implement the "Empty Event Handler" diagnostic for empty event handlers and don't show diagnostic for handlers with "throw" statements, as it was in CodeRush Classic. We will try to implement such functionality as soon as possible, and when we will have any progress on the issue, we notify you in context of this ticket.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.