473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Conditional compilation?

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
Nov 16 '05 #1
4 2721
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.

Nov 16 '05 #2
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
Nov 16 '05 #3
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.

"David Veeneman" wrote:
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

Nov 16 '05 #4
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.

"David Veeneman" wrote:
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

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
2
by: Steve Jorgensen | last post by:
To begin with an example... Let's say you were wanting to write code usign early binding to the MSXML library, but then be able to switch between early and late binding at will. Conditional...
1
by: chris han | last post by:
Hi, all, I'm trying to use Conditional Compilation Statements in my code. using System; #define DEBUG public class MyClass { public static void Main() {
12
by: wanghz | last post by:
Hi, Could I ask some questions about the conditional compilaion? Suppose I have three simple files: a.c, b.c and c.h /* --------a.c--------- */ #include <stdio.h> #include "c.h" int...
2
by: FireStarter | last post by:
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...
1
by: A.M-SG | last post by:
Hi, We have a solution with several c# projects within it. How can I define solution wide conditional compilation symbols?
4
by: Bob | last post by:
Hi, In VS2003 conditional compilation constants and their state could be defined at project level. I was using this to control what features where offered by various builds. i.e....
10
by: Dave | last post by:
I'm a C++ programmer of many years, trying to get my feet wet in C#. I have a question about conditional compilation. In C++, I would sometimes define a constant in an include file, and then...
1
by: Marek | last post by:
I use VS2005 with framework 2.0 and I just found a behavior I consider odd. Here is the code that illustrates th eproblem: public static void MethodA() { MethodB() } #if DEBUG
6
by: maxwell | last post by:
I'm trying to use the gpp utility (Gnu points to http://en.nothingisreal.com/wiki/GPP) to do conditional compilation in Python, and I'm running into a problem: the same '#' character introduces...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.