471,353 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,353 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 1572
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Québec | last post: by
11 posts views Thread by Steven T. Hatton | last post: by
12 posts views Thread by wanghz | last post: by
2 posts views Thread by FireStarter | last post: by
4 posts views Thread by Bob | last post: by
1 post views Thread by Marek | last post: by
6 posts views Thread by maxwell | last post: by

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.