Gendarme.Rules.Performance.UseIsOperatorRule Class
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.

See Also: UseIsOperatorRule Members

Syntax

[Gendarme.Framework.EngineDependency(typeof(Gendarme.Framework.Engines.OpCodeEngine, Gendarme.Framework, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null))]
[Gendarme.Framework.Problem("The method should use the "is" operator and avoid the cast and comparison to null.")]
[Gendarme.Framework.Solution("Replace the cast and compare to null with the simpler "is" operator.")]
public class UseIsOperatorRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule

Remarks

This rule is available since Gendarme 2.0

Example

Bad example:

Example

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

Example

Good example:

Example

            bool is_my_type = (my_instance is MyType);
            

Requirements

Namespace: Gendarme.Rules.Performance
Assembly: Gendarme.Rules.Performance (in Gendarme.Rules.Performance.dll)
Assembly Versions: 2.8.0.0