Skip to content

Gendarme.Rules.BadPractice.DisableDebuggingCodeRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

DisableDebuggingCodeRule

Assembly: Gendarme.Rules.BadPractice
Version: 2.10

Description

This rule checks for non-console applications which contain calls to Console.WriteLine. These are often used as debugging aids but such code should be removed or disabled in the released version. If you don't want to remove it altogether you can place it inside a method decorated with Conditional ("DEBUG"), use Debug.WriteLine, use Trace.WriteLine, or use the preprocessor. But note that TRACE is often enabled in release builds so if you do use that you'll probably want to use a config file to remove the default trace listener.

Examples

Bad example:

private byte[] GenerateKey ()
{
    byte[] key = new byte[16];
    rng.GetBytes (key);
    Console.WriteLine ("debug key = {0}", BitConverter.ToString (key));
    return key;
}

Good example (removed):

private byte[] GenerateKey ()
{
    byte[] key = new byte[16];
    rng.GetBytes (key);
    return key;
}

Good example (changed):

private byte[] GenerateKey ()
{
    byte[] key = new byte[16];
    rng.GetBytes (key);
    Debug.WriteLine ("debug key = {0}", BitConverter.ToString (key));
    return key;
}

Notes

  • This rule is available since Gendarme 2.0
Clone this wiki locally