Conditional compilation attribute

  • Thread starter Thread starter vooose
  • Start date Start date
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
 
"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
 
"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
 
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
 
Back
Top