Issue with Redundent Explicit Delegate Creation
I looked through the forum and couldnt find anything on this. I understand what the error means but not sure how it applies to this case.
I get the error on all my asp pages for all event handlers.
btnSave.Click += new EventHandler(btnSave_Click);
new EventHandler is flagged with the 'Redundent Explicit Delegate Creation' warning. I could just disable the warning but there has to be a reason. Am I missing something?
Please sign in to leave a comment.
You don't need to specify that the delegate as an EventHandler, because the
compiler already knows what it is.
ReSharper is offering to change this:
btnSave.Click += new EventHandler(btnSave_Click);
to this:
btnSave.Click += btnSave_Click;
Which is a bit nicer to look at, I think.
---
Richard
"Artin Bannayan" <abannayan@mac.com> wrote in message
news:8316223.1183122980335.JavaMail.itn@is.intellij.net...
>I looked through the forum and couldnt find anything on this. I understand
>what the error means but not sure how it applies to this case.
>
>
>
Thanks for the reply Richard.
Must admit I never knew I could do that. This is must be a new check with 3.0.
Now I've been using resharper for a long time now that I don't really remember what comes from VS and Resharper. However when I build an event handler the code completion still wants to put in the handler name. I like using this because it creates the method with the correct signature for me (lazy I know). So now we're stuck with always editing the wiring after the fact or doing it completely manually which seems more effort than its worth. I tried to see if there was a way to change this behaviour but I couldn't find it. Would be nice if this behavior was changed with the new code checking. Just my 2 cents.
Artin
You can just type:
or any other method name (depending on your coding tastes) :)
ReSharper will color the OnSave token in red. Place the cursor on the method (it is most likely already there), press Alt+Enter (keyboard shortcut for the lightbulb) and select the Create Method quick fix and ReSharper will create the method with the correct signature.
I like this method more than the VS built in Tab metaphor. You just enter the method name that you want and let R# do the rest...
Hello James,
I prefer to use smart-completion for this purpose.
See http://resharper.blogspot.com/2007/05/code-completion-with-resharper.html
for more info, down to Smart Completion section.
Sincerely,
Ilya Ryzhenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
IR> You can just type:
IR>
IR> or any other method name (depending on your coding tastes) :)
IR>
IR>
IR> ReSharper will color the OnSave token in red. Place the
IR> cursor on the method (it is most likely already there), press
IR> Alt+Enter (keyboard shortcut for the lightbulb) and select
IR> the Create Method quick fix and ReSharper will create the
IR> method with the correct signature.
IR>
IR> I like this method more than the VS built in Tab metaphor. You just
IR> enter the method name that you want and let R# do the rest...
IR>
I just tried out the smart completion for this use case. You guys rock! (most of the time :) )