T
Theon Greyjoy
Hi all,
I have a code behind file which I would like to conditionally compile
parts of.
The code is in C#. here is what I want to achieve, in pseudo C++ style:
--------------------------------
#define PRODUCTION 1
public partial class _MyPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#ifdef PRODUCTION
// My code
#endif
}
protected void button1_Click(object sender, EventArgs e)
{
#ifndef PRODUCTION
// More code
#endif
}
protected void button2_Click(object sender, EventArgs e)
{
#ifndef PRODUCTION
// More code again
#endif
}
}
-----------------------------------
In the above, you would think that the code in Page_Load would be
compiled, and the code in the button click events would not be.
Vice-versa if I removed the #define line.
However, I get the error "Cannot define/undefine preprocessor symbols
after first token in file" for the #define line. I've tried putting it
above and below the using statements, inside the class, with and without
a semi-colon, etc, but I can't get it to work. Is it because the class
is partial? Any other ideas?
Thanks in advance,
-Theon
I have a code behind file which I would like to conditionally compile
parts of.
The code is in C#. here is what I want to achieve, in pseudo C++ style:
--------------------------------
#define PRODUCTION 1
public partial class _MyPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#ifdef PRODUCTION
// My code
#endif
}
protected void button1_Click(object sender, EventArgs e)
{
#ifndef PRODUCTION
// More code
#endif
}
protected void button2_Click(object sender, EventArgs e)
{
#ifndef PRODUCTION
// More code again
#endif
}
}
-----------------------------------
In the above, you would think that the code in Page_Load would be
compiled, and the code in the button click events would not be.
Vice-versa if I removed the #define line.
However, I get the error "Cannot define/undefine preprocessor symbols
after first token in file" for the #define line. I've tried putting it
above and below the using statements, inside the class, with and without
a semi-colon, etc, but I can't get it to work. Is it because the class
is partial? Any other ideas?
Thanks in advance,
-Theon