473,397 Members | 2,068 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,397 software developers and data experts.

Debug Constant

This is going to be really stupid...but I often define method/properties
with an Attribute of Debug. When I compile for build, they cease to exist.
This is cool. However, is there a constant to the inverse? What I want to
do is if I have a Debug Build, I want to skip all sorts of log-on stuff and
the like. Right now, I'm manually setting a property in the build
properties, but I was wondering if there is a more elegant way to do it..ie
with Trace/Release or whatever else (I've tried these already).

Thanks,

Bill
Jul 21 '05 #1
3 8220
William Ryan <do********@nospam.comcast.net> wrote:
This is going to be really stupid...but I often define method/properties
with an Attribute of Debug. When I compile for build, they cease to exist.
This is cool. However, is there a constant to the inverse? What I want to
do is if I have a Debug Build, I want to skip all sorts of log-on stuff and
the like. Right now, I'm manually setting a property in the build
properties, but I was wondering if there is a more elegant way to do it..ie
with Trace/Release or whatever else (I've tried these already).


There isn't an actual attribute called Debug as far as I'm aware -
however, there *is* the Conditional attribute, which can take any
string in its constructor as a symbol name, and if that symbol is
undefined the method/property won't be compiled (assuming the compiler
understands the attribute). You can just change your build settings to
define the symbol RELEASE, and use

[Conditional("RELEASE")]

in your code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
You can also use conditional compilation with defined symbols in the same
manner you would in C or C++. As in...

public void MyLoginMethod()
{
#if DEBUG
// some code here
#else
//other code here
#endif
}

One rule is that symbols defined in a source file must be before any other
C# statements. So put all the defines at the very top of the file, followed
by the using statements.

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
William Ryan <do********@nospam.comcast.net> wrote:
This is going to be really stupid...but I often define method/properties
with an Attribute of Debug. When I compile for build, they cease to exist. This is cool. However, is there a constant to the inverse? What I want to do is if I have a Debug Build, I want to skip all sorts of log-on stuff and the like. Right now, I'm manually setting a property in the build
properties, but I was wondering if there is a more elegant way to do it..ie with Trace/Release or whatever else (I've tried these already).


There isn't an actual attribute called Debug as far as I'm aware -
however, there *is* the Conditional attribute, which can take any
string in its constructor as a symbol name, and if that symbol is
undefined the method/property won't be compiled (assuming the compiler
understands the attribute). You can just change your build settings to
define the symbol RELEASE, and use

[Conditional("RELEASE")]

in your code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
Thanks both of you. I have used the # directives previsouly, but then I
saw there was a conditional debug attribute which worked cool, but I wanted
to have some code only execute for release builds. I tried using Release
but it didn't seem to work. Let me try it again though.

I can use the named directives, I was just wondering if there was a more
attribute focues way to do it.

Thanks again,

Bill
"Dave" <dl*********@wi.rr.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
You can also use conditional compilation with defined symbols in the same
manner you would in C or C++. As in...

public void MyLoginMethod()
{
#if DEBUG
// some code here
#else
//other code here
#endif
}

One rule is that symbols defined in a source file must be before any other
C# statements. So put all the defines at the very top of the file, followed by the using statements.

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
William Ryan <do********@nospam.comcast.net> wrote:
This is going to be really stupid...but I often define method/properties with an Attribute of Debug. When I compile for build, they cease to exist. This is cool. However, is there a constant to the inverse? What I
want
to do is if I have a Debug Build, I want to skip all sorts of log-on
stuff
and the like. Right now, I'm manually setting a property in the build
properties, but I was wondering if there is a more elegant way to do it..ie with Trace/Release or whatever else (I've tried these already).


There isn't an actual attribute called Debug as far as I'm aware -
however, there *is* the Conditional attribute, which can take any
string in its constructor as a symbol name, and if that symbol is
undefined the method/property won't be compiled (assuming the compiler
understands the attribute). You can just change your build settings to
define the symbol RELEASE, and use

[Conditional("RELEASE")]

in your code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Jul 21 '05 #4

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

Similar topics

4
by: Claire | last post by:
How do I determine whether Im running in debug or release mode from code please. thanks Claire
3
by: Max M. Power | last post by:
How can I tell if my C# code is running in debug mode? I need to execute some extra code only when my project has been compiled in debug mode. In release mode I don't want to execute this extra...
7
by: Tom | last post by:
How can I make code not execute for a debug build, but do execute for a production build? I have code which prompts for an account and password when the program starts up. It is a pain to have to...
3
by: William Ryan | last post by:
This is going to be really stupid...but I often define method/properties with an Attribute of Debug. When I compile for build, they cease to exist. This is cool. However, is there a constant to...
6
by: swartzbill2000 | last post by:
Hello, I have a VB 2005 Express project with a TraceListener-derived class to route Debug.Print output to a log file. It works fine for Debug builds. What is the correct combination of changes to...
4
by: Brett Romero | last post by:
Say I have this setup: public static void SomeMethod() { #if DEBUG .... #endif }
3
by: =?Utf-8?B?ZWxhZGxh?= | last post by:
Hi. I was wondering if it was possible to give a variable different values depending on if the code was compiled in debug or release? i.e. if the code was compiled in debug: string...
3
by: rorni | last post by:
Hi, I'm porting code from Windows to HP-UX 11, compiling with g++. I'm getting a compilation error on the system's debug.h include file, which is included very indirectly through a series of...
7
by: Khookie | last post by:
Hi everyone The program I'm writing is getting bigger, hence not as easy to debug. So I have this on one of my core header files, which I include in just about every .c file, and I use it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.