Conditional DEBUG - Does it still compile into RELEASE code?
Asked Answered
H

1

6

I know that if I mark code as DEBUG code it won't run in RELEASE mode, but does it still get compiled into an assembly? I just wanna make sure my assembly isn't bloated by extra methods.

[Conditional(DEBUG)]
private void DoSomeLocalDebugging()
{
   //debugging
}
Hetzel answered 13/8, 2010 at 13:41 Comment(0)
F
11

Yes, the method itself still is built however you compile.

This is entirely logical - because the point of Conditional is to depend on the preprocessor symbols defined when the caller is built, not when the callee is built.

Simple test - build this:

using System;
using System.Diagnostics;

class Test
{
    [Conditional("FOO")]
    static void CallMe()
    {
        Console.WriteLine("Called");
    }

    static void Main()
    {
        CallMe();
    }
}

Run the code (without defining FOO) and you'll see there's no output, but if you look in Reflector you'll see the method is still there.

To put it another way: do you think the .NET released assemblies (the ones we compile against) are built with the DEBUG symbol defined? If they're not (and I strongly suspect they're not!) how would we be able to call Debug.Assert etc?

Admittedly when you're building private methods it would make sense not to include it - but as you can see, it still is built - which is reasonable for simplicity and consistency.

Fahland answered 13/8, 2010 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.