conditional methods

M

Mark

Conditional methods are throwing me for a loop. I understand that if I
compile the BLAH class code below in a Release mode project, it will not
include the "Message" method. However, let's say that I have another method
that CALLS this method, like the foobar class. Won't the compiler bomb? Or
would its "CallTheOtherMethod" method just not exist either?

Thanks in advance.

Mark

public class blah
{
[Conditional("DEBUG")]
public static void Message (string myString)
{
Console.WriteLine("Neat - " + myString);
}
}

public class foobar
{
public static void CallTheOtherMethod()
{
blah.Message("Won't this bomb when compiled in release mode?");
}
}
 
D

Daniel O'Connell [C# MVP]

Mark said:
Conditional methods are throwing me for a loop. I understand that if I
compile the BLAH class code below in a Release mode project, it will not
include the "Message" method. However, let's say that I have another
method
that CALLS this method, like the foobar class. Won't the compiler bomb?
Or
would its "CallTheOtherMethod" method just not exist either?

CallTheOtherMethod would simply not have the method call to the conditinoal
method. The compiler doesn't emit the call.
 
M

Mattias Sjögren

I understand that if I
compile the BLAH class code below in a Release mode project, it will not
include the "Message" method.

Yes it will. Only calls to the method are excluded.



Mattias
 

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