Conditional compilation?

  • Thread starter Thread starter David Veeneman
  • Start date Start date
D

David Veeneman

I'm creating several public properties in a class that I will use
exclusively for testing purposes. In a Debug compile, I want these
properties to be included in the compile, but I want them omitted from a
Release compile. What is the easiest way to accomplish this goal in VS.Net,
using C#? Conditional Methods won't work, since I want to make properties,
not methods, conditional. I could enclose the conditional properties within
a #if ... #endif block, and use a #define at the top of the file to control
the condition.

But is there a simpler way to do what I want to do? Thanks

David Veeneman
Foresight Systems
 
Rather than using conditional compilation, you could create a test
version of the class that inherits from the real version and adds the
test methods.
 
Thanks-- that's a good idea. I discovered that if I enclose the test
properties in an <#if DEBUG ... #endif> block, I can omit the #define
statement. VS.Net is smart enough to recognize the #if conditional and
handle it appropriately. If the build configuration is set to 'Debug', the
code is compiled. If the configuration is set to 'Release', the code is not
compiled. That keeps me from having to reset the #define statement in every
class where I have test properties before and after every release compile.

David Veeneman
Foresight Systems
 
because DEBUG symbol is defined when you compile it in debug mode. you can
add additional symbols by using the /define option of csc.exe. you don't
have to use #define on every page.
 
Back
Top