Hi,
I think that it depend in which pass the different elements are parsed.
I'm not 100% sure of the next as my experience with the compilation process
is not that deep but it's valid in the "old" C world
the #undef DBG is a preprocessor directive , it's handle before the code
really reach a semantic or syntax parse, this is the first step to compile
the source code, this preprocesor get rid of the part that will not be
compiled therefore the compiler never sees the gargabe you write in this
part:
#if DBG
// garbage here, that does not generate
// compilation errors - correct
x*&$%bbb
#endif
Now if you use [Conditional("DBG")] this is not a preprocessor directive and
therefore it leave it there for the compiler to see, when it does reach the
compiler and it start doing the syntax parsing ( I think remember it's done
first than the semantic ) it see the wrong code and report it as error.
This must be more or less the process.
Hope this help,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"FireStarter" <em***@server.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Guys, in the code that follows, why does the method F() still compile,
even if DBG is undefined? Inside method G(), the code inside <#if DBG> does not
compile (notice that I can write whatever I want in there, I will not receive a
compilation error). I do get such an error in F() - because of the garbage
I intentionally put there - but F() should not compile in the first place.
Am I misusing this [Conditional...] attribute?!
#undef DBG
using System.Diagnostics;
class Class1 {
public Class1() {
int y = 0;
}
public void G() {
int x = 0;
x++;
#if DBG
// garbage here, that does not generate
// compilation errors - correct
x*&$%bbb
#endif
}
[Conditional("DBG")]
public void F() {
// garbage here, that generates compilation errors,
// although this is a conditional method, and DBG is undefined
x*&$%bbb
}
}