Skip to content

Gendarme.Rules.BadPractice.ToStringShouldNotReturnNullRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

ToStringShouldNotReturnNullRule

Assembly: Gendarme.Rules.BadPractice
Version: git

Description

This rule checks for overridden ToString() methods which return null. An appropriately descriptive string, or string.Empty, should be returned instead in order to make the value more useful (especially in debugging).

Examples

Bad example:

public override string ToString ()
{
    return (count == 0) ? null : count.ToString ();
}

Good example:

public override string ToString ()
{
    return count.ToString ();
}

Notes

  • Before Gendarme 2.4 this rule was named ToStringReturnsNull.

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally