Skip to content

Gendarme.Rules.BadPractice.DisableDebuggingCodeRule(git)

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

DisableDebuggingCodeRule

Assembly: Gendarme.Rules.BadPractice
Version: git

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

Source code

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

Clone this wiki locally