Gendarme.Rules.Performance.AvoidTypeGetTypeForConstantStringsRule Class
This rule warns when a method use Type.GetType(string) with a constant string. Such calls requires reflection in order to return a Type instance and, for known types, can be replaced with a much faster typeof(x).

See Also: AvoidTypeGetTypeForConstantStringsRule Members

Syntax

[Gendarme.Framework.EngineDependency(typeof(Gendarme.Framework.Engines.OpCodeEngine, Gendarme.Framework, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null))]
[Gendarme.Framework.Problem("This method calls Type.GetType(string) on a constant string. This call requires reflection in order return an instance of the type.")]
[Gendarme.Framework.Solution("For known values it is faster to use typeof(x), C# syntax, to obtain the same result without the reflection penality.")]
public class AvoidTypeGetTypeForConstantStringsRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule

Remarks

This rule is available since Gendarme 2.0

Example

Bad example:

Example

            booleanType = Type.GetType ("System.Boolean");
            

Example

Good example:

Example

            booleanType = typeof (bool);
            

Requirements

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