One of the cleanup is this (there were 3 of them in Mono corlib):
- return value as EncoderExceptionFallback != null;
+ return (value is EncoderExceptionFallback);
This looks like a perfect candidate for Gendarme rule. So I quickly
wrote one and confirmed that there are no more of these. The file is
attached.
I meant to write Gendarme rule for a while, but this is my first try.
Please comment!
--
Seo Sanghyeon
On mié, 2008-01-09 at 21:28 +0900, Sanghyeon Seo wrote:
> On Mono-dev, Juraj Skripsky posted a patch to cleanup "as" casts.
> (CC'ing him...)
> http://lists.ximian.com/pipermail/mono-devel-list/2008-January/026508.html
>
> One of the cleanup is this (there were 3 of them in Mono corlib):
> - return value as EncoderExceptionFallback != null;
> + return (value is EncoderExceptionFallback);
>
> This looks like a perfect candidate for Gendarme rule. So I quickly
> wrote one and confirmed that there are no more of these. The file is
> attached.
Sure :)
> I meant to write Gendarme rule for a while, but this is my first try.
> Please comment!
I have only a little comment (Sebastien commented the others), in this
line:
InstructionCollection instructions = method.Body.Instructions;
Before get the Instructions, you should check if the method has body
with the HasBody property, this is because the Gendarme runner will
check also abstract methods, or PInvoke methods or any other method
without body. If you try to access to a method without instructions you
will get an exception.
Finally, you can see some tips and suggestions in this page:
http://groups.google.com/group/gendarme/web/how-to-write-cool-rules
Good work, and thanks !
Néstor.