Skip to content

Gendarme.Rules.BadPractice.ToStringShouldNotReturnNullRule(2.10)

Sebastien Pouliot edited this page Jan 22, 2011 · 2 revisions

ToStringShouldNotReturnNullRule

Assembly: Gendarme.Rules.BadPractice
Version: 2.10

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.
Clone this wiki locally