Checking DEBUG constant from different assembly?

B

Brett Romero

Say I have this setup:

[A.DLL]
public static void SomeMethod()
{
#if DEBUG
....
#endif
}

[B.EXE]
A.Class1.SomeMethod();

In A.DLL's project property build tab, DEBUG constant is turned off
while it is one for B.EXE. This isn't transient however. The code
doesn't execute. A.DLL has to have the DEBUG constant turned on, which
will always run the code. I want the caller to determine if the code
should run or not. Any suggestions?

Thanks,
Brett
 
J

Jon Skeet [C# MVP]

Brett Romero said:
Say I have this setup:

[A.DLL]
public static void SomeMethod()
{
#if DEBUG
....
#endif
}

[B.EXE]
A.Class1.SomeMethod();

In A.DLL's project property build tab, DEBUG constant is turned off
while it is one for B.EXE. This isn't transient however. The code
doesn't execute. A.DLL has to have the DEBUG constant turned on, which
will always run the code. I want the caller to determine if the code
should run or not. Any suggestions?

I don't believe there's a way of doing this with pre-processor symbols.
You'd need to use a normal variable of some description.

I feel your pain though - it means that if you want to let people debug
through your code etc, you need to publish two versions of libraries -
a debug version and a release version :(
 
B

Brett Romero

I basically have to create some parameter flag than to pass into each
of these methods? Maybe it isn't so bad. I can create a static bool
var in B.EXE's program.cs (or what ever the startup file is) and just
reference it from there. I could also probably use the app.config to
get the flag value. That sound work able?

Thanks,
Brett
 
J

Jon Skeet [C# MVP]

Brett Romero said:
I basically have to create some parameter flag than to pass into each
of these methods? Maybe it isn't so bad. I can create a static bool
var in B.EXE's program.cs (or what ever the startup file is) and just
reference it from there. I could also probably use the app.config to
get the flag value. That sound work able?

Well, I'd have a property in A.dll which can be set by B.exe - it's a
pain to have to pass it on every method call. You almost certainly
won't be able to reference a property in B.exe from A.dll - normally an
executable references a class library, not the other way round.
 
B

Brett Romero

That's what I'm referring to but in B.exe I want a simple way to turn
that property on/off. Basically I want the method contents to execute
if the property is true and not if false. It's a debug switch more or
less.

I guess what I'm asking is, how do I set something in the B.exe
app.config file, which B.exe can read and set the value of a static
variable that is used across B.exe? I'll then pass that static var
into the constructor of the A.DLL object, which is the condition to
execute the method code or not. Now I have a switch that can be turned
on/off from the app.config file.

Thanks,
Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top