~ubuntu-branches/debian/sid/mono-tools/sid

« back to all changes in this revision

Viewing changes to gendarme/rules/Gendarme.Rules.Performance/DontIgnoreMethodResultRule.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-13 09:08:47 UTC
  • mfrom: (14.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20100913090847-lhu3z021w2azaj8q
Tags: 2.6.2-3
Upload to Debian Unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
namespace Gendarme.Rules.Performance {
42
42
 
43
43
        /// <summary>
44
 
        /// This rule detects when some code doesn't use the return value of a method call. 
45
 
        /// Since any returned object potentially requires memory allocations this impacts 
46
 
        /// performance. Furthermore this often indicates that the code might not be doing 
47
 
        /// what is expected. This is seen frequently on <c>string</c> where people forgets 
48
 
        /// their immutability. There are some special cases, e.g. <c>StringBuilder</c>, where 
49
 
        /// some methods returns the current instance (to chain calls). The rule will ignore 
50
 
        /// those well known cases. 
 
44
        /// This rule fires if a method is called that returns a new instance but that instance
 
45
        /// is not used. This is a performance problem because it is wasteful to create and
 
46
        /// collect objects which are never actually used. It may also indicate a logic problem.
 
47
        /// Note that this rule currently only checks methods within a small number of System
 
48
        /// types.
51
49
        /// </summary>
52
50
        /// <example>
53
51
        /// Bad example:
55
53
        /// public void GetName ()
56
54
        /// {
57
55
        ///     string name = Console.ReadLine ();
58
 
        ///     // a new trimmed string is created by never assigned to anything
59
 
        ///     // but name itself is unchanged
 
56
        ///     // This is a bug: strings are (mostly) immutable so Trim leaves
 
57
        ///     // name untouched and returns a new string.
60
58
        ///     name.Trim ();
61
59
        ///     Console.WriteLine ("Name: {0}", name);
62
60
        /// }
74
72
        /// </code>
75
73
        /// </example>
76
74
 
77
 
        [Problem ("The method ignores the result value from the specified call.")]
78
 
        [Solution ("You shouldn't ignore the result value.")]
 
75
        [Problem ("The method ignores the result value from a method call.")]
 
76
        [Solution ("Don't ignore the result value.")]
79
77
        [EngineDependency (typeof (OpCodeEngine))]
80
78
        [FxCopCompatibility ("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults")]
81
79
        public class DoNotIgnoreMethodResultRule : Rule, IMethodRule {