Gendarme.Rules.Performance.AvoidUnneededCallsOnStringRule Class
This rule detects when some methods, like Clone(), Substring(0), ToString() or ToString(IFormatProvider), are being called on a string instance. Since these calls all return the original string they don't do anything useful and should be carefully reviewed to see if they are working as intended and, if they are, the method call can be removed.

See Also: AvoidUnneededCallsOnStringRule 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 needlessly calls some method(s) on a string instance. This may produce some performance penalities.")]
[Gendarme.Framework.Solution("Remove the unneeded call(s) on the string instance.")]
public class AvoidUnneededCallsOnStringRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule

Remarks

Prior to Gendarme 2.0 this rule was more limited and named AvoidToStringOnStringsRule

Example

Bad example:

Example

            public void PrintName (string name)
            {
            	Console.WriteLine ("Name: {0}", name.ToString ());
            }
            

Example

Good example:

Example

            public void PrintName (string name)
            {
            	Console.WriteLine ("Name: {0}", name);
            }
            

Requirements

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