Conditional compilation attribute

V

vooose

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
 
J

jmcgrew

"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
 
V

vooose

"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
 
T

Truong Hong Thi

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top