Description: There are some delegates used as event handler which
haven't the correct signature, bad returning type or parameter names.
References: http://msdn.microsoft.com/en-us/library/ms182133(VS.80).aspx
http://blogs.msdn.com/fxcop/archive/2007/08/09/what-rules-do-microsoft-have-turned-on-internally.aspx
Good example:
public delegate void BarHandler (object sender, EventArgs e);
public class Foo {
public event BarHandler OnBar;
}
Bad example:
public delegate int BarHandler (object obj, EventArgs args);
public class Foo {
public event BarHandler OnBar;
}
Well, this will be the latest rule and I would like to explore new ways
of checking. I have never wrote a rule for events, and I think new
problems could be found with the events (and also new rules written).
Comments?
Néstor.
This happens to be a point where I disagree with the FDG -- I prefer
the use of (sender, args) instead of (sender, e). However, I guess the
rule only checks in the delegate, where it's not such a big deal for
me. I can go on "misnaming" it in my actual event handler methods :-)
--
Michael Hutchinson
http://mjhutchinson.com
El sáb, 16-08-2008 a las 15:53 -0400, Michael Hutchinson escribió:
> This happens to be a point where I disagree with the FDG -- I prefer
> the use of (sender, args) instead of (sender, e). However, I guess the
> rule only checks in the delegate, where it's not such a big deal for
> me. I can go on "misnaming" it in my actual event handler methods :-)
Yes, I agree with you. I also prefer name the second parameter as
args, because is more descriptive than e.
Anyways, the parameter names violation, won't have a high severity.
And if someone more agree, I can add "args" as a valid name too.
Thanks for your feedback Michael :)
Néstor.
Make sure you commit everything you have (even if not 100% complete /
reviewed) before GSoC deadline!
August 18:
~12 noon PDT / 19:00 UTC Firm 'pencils down' date. Mentors, students and
organization administrators can begin submitting final evaluations to
Google.
Sebastien
or you can:
(a) turn off this rule (e.g. your own rules.config)
but that's not very interesting (to me ;-) unless you also do the next
two steps
(b) create your own rule (by inheriting from this one) and override the
parameter check
(c) add this new rule/assembly to your own rules.config
Sebastien