"Conditional" attribute confusion

M

Marek

I use VS2005 with framework 2.0 and I just found a behavior I consider odd.
Here is the code that illustrates th eproblem:

[Conditional("DEBUG")]
public static void MethodA()
{
MethodB()
}

#if DEBUG
public static void MethodB()
{
....
}
#endif

my expectation was that this code will compile perfectly when DEBUG
condition is defined as well as when it is undefined. Apparently, that is
not the case. When compiling with "DEBUG" undefined, compiler generates
error: "The name MethodB does not exist in current context."

This is what Microsoft help says about ConditionalAttribute class:
"Indicates to compilers that a method call or attribute should be ignored
unless a specified conditional compilation symbol is defined". The
conclusion from this is that MethodA from my example should not be compiled.
The reality is that the nethod is compiled - otherwise the error would not
have been reported.

Is there something I am missing about "Conditional" attribute and how the
compiler is working or it something .NET framework documentation or/and C#
compiler are missing ?

Thank you.
 
M

Marek

Well, 2 minutes after I submitted this post I found the answer to my
question. Certainly it was me missing the point. "Conditional" attribute
informs compiler to ignore the call to the method but not to ignore the
method during the compilation.

My apology for posting something that I should not have.
 

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