History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: RSRP-55342
Type: New Feature New Feature
Status: Open Open
Priority: Normal Normal
Assignee: Sergey Shkredov
Reporter: Alex Martsynkevich
Votes: 2
Watchers: 5
Operations

If you were logged in you would be able to see more operations.
ReSharper

Add "remove empty event handler"

Created: 03 Jan 08 02:17   Updated: 14 Apr 08 15:02
Component/s: Refactorings - Safe Delete
Fix Version/s: 4.5
Security Level: Everybody (All jira users)

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
File Attachments: None
Image Attachments:

1. RemoveEmptyHandler.png
(9 kb)


 Description  « Hide
Along with "safe delete", add "remove empty event handler" refactoring action to a method, if it is empty, private and used only with += and -= operators for some delegate/event. Since method has usages it cannot be marked as "unused". Action should remove these usages as well.

 All   Comments   Work Log   Change History      Sort Order:
Ilya Ryzhenkov - 14 Jan 08 13:47
It is not always safe to delete such method. If it is assumed, that there are always at least one subscriber, there could be ommitted checks for null. Like this:
public event EventHandler SomethingChanged = EmptyHandler;

private void EmptyHandler(object sender, EventArgs e) {};

protected virtual void OnSomethingChanged(EventArgs e)
{
 SomethingChanged(this, e); // not check for null is ommited
}

Alex Martsynkevich - 14 Jan 08 15:36
Right, that's why I suggest to add this feature as another refactoring function, not the same as "safe delete". In most cases (and it is a proper behavior) there's a check whether delegate is null before invoking it.
In fact, I'd even suggest considering allowing this feature on non-empty event handlers. It would be a useful shortcut, since the method and it's usage are likely to be quite far apart in the code. As long as user can undo the action.

Ilya Ryzhenkov - 14 Jan 08 15:50
As far as I understand, we just need to remove subscribe/unsubscribe usages when safe-deleting method. Probably also suppress conflict if method is void and empty. Then you can easily do what you want by ignoring conflicts, if they appear. Am I right?

Ilya Ryzhenkov - 16 Jan 08 12:49
So, why safe delete with described additions won't work for you?

Alex Martsynkevich - 16 Jan 08 15:31
If safe delete dialog removes usages (perhaps, also marks them with something lower than "stop" severity at conflicts step), I don't see a problem with it. You're right – one less context action is probably a better way.