Gendarme.Rules.Performance.DoNotIgnoreMethodResultRule Class
This rule fires if a method is called that returns a new instance but that instance is not used. This is a performance problem because it is wasteful to create and collect objects which are never actually used. It may also indicate a logic problem. Note that this rule currently only checks methods within a small number of System types.

See Also: DoNotIgnoreMethodResultRule Members

Syntax

[Gendarme.Framework.EngineDependency(typeof(Gendarme.Framework.Engines.OpCodeEngine, Gendarme.Framework, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null))]
[Gendarme.Framework.FxCopCompatibility("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults")]
[Gendarme.Framework.Problem("The method ignores the result value from a method call.")]
[Gendarme.Framework.Solution("Don't ignore the result value.")]
public class DoNotIgnoreMethodResultRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule

Remarks

Documentation for this section has not yet been entered.

Example

Bad example:

Example

            public void GetName ()
            {
            	string name = Console.ReadLine ();
            	// This is a bug: strings are (mostly) immutable so Trim leaves
            	// name untouched and returns a new string.
            	name.Trim ();
            	Console.WriteLine ("Name: {0}", name);
            }
            

Example

Good example:

Example

            public void GetName ()
            {
            	string name = Console.ReadLine ();
            	name = name.Trim ();
            	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