Skip to content

Gendarme.Rules.Performance.UseIsOperatorRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

UseIsOperatorRule

Assembly: Gendarme.Rules.Performance
Version: 2.10

Description

This rule looks for complex cast operations (e.g. a as with a null check) that can be simplified using the is operator (C# syntax). Note: in some case a compiler, like [g]mcs, can optimize the code and generate IL identical to a is operator. In this case the rule will not report an error even if you could see one while looking the at source code.

Examples

Bad example:

bool is_my_type = (my_instance as MyType) != null;

Good example:

bool is_my_type = (my_instance is MyType);

Notes

  • This rule is available since Gendarme 2.0
Clone this wiki locally