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

Conditional compilation attribute

Consider a class property:

private int field;
public Order Field
{
get { return this.field; }
set { this.field= value; }
}

Is there any way to omit the setter if, say, DEBUG is defined?

I don't want to do:
#if !DEBUG
set { this.field= value; }
#endif

I would prefer:

[OmitThisMethod(DEBUG)]
set { this.field= value; }

Using [Conditional("DEBUG")] does not solve this as I want to get a
compile error if someone attempts to set the field

Regards

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Dec 1 '05 #1
3 1620
"I want to get a compile error if someone attempts to set the field"

Isn't that exactly what will happen if you use your first solution,
putting the set accessor inside an #if block?

Or do you mean you want DEBUG to be defined in the file that's
*setting* the property, not the file where it's defined? In that case,
I think the answer is no, you can't do that (without a modified
compiler).

Jesse

Dec 1 '05 #2
"Isn't that exactly what will happen if you use your first solution,
putting the set accessor inside an #if block?"

Yes! But I don't like #if/#endif...it is ugly. I would prefer a method
attribute

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Dec 1 '05 #3
If you don't want to use directives, I am afraid no way. As far as I
know, currently there is not a way to define a compile-time attribute
and instruct the compiler to use it.

Thi

Dec 1 '05 #4

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

Similar topics

10
by: Québec | last post by:
Hi every body, What does that mean? The following script raises the subject alarm. <p><a href="javascript:void();" onClick="mailto:sgagnon@cyberus.ca?Subject=BRITTANY&nbsp;WORKSHOP"> <img...
4
by: Zarko Gajic | last post by:
Hi, Is there a way to include an #If ... directive in my code to enable conditional compilation based on the framework version? The idea is to be able to compile the "same" code for both the...
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...
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...
7
by: John Dolinka | last post by:
I have a project of several files with #defines to setup a conditional compile. I would like to put these #defines in a single file and change the conditional compile from this one file with the...
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....
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...
10
by: VK | last post by:
Taking into account many new features in JavaScript1.6 and JavaScript1.7 which are syntactically incompatible with Javascript versions run on other browsers: would it be reasonable to propose as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...

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.