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.