views:

122

answers:

1

Is there an analogous conditional-not-present attribute or maybe a way to use the Conditional attribute to only include a method if that symbol is not defined?

What I'm looking for is something that works like this:

[Conditional("!SILVERLIGHT")]
private void DoStuffThatSilverlightCant() {...}

Such that the method will not be included if the symbol SILVERLIGHT does exist.

The reason I don't want to use a simple #ifdef is so that I can take advantage of the compiler removing the calling statements without having to wrap every individual call in an #ifdef.

+4  A: 

Update: The following code snippet only works if the #if is in every calling file which is not very practical.

#if !SILVERLIGHT
#define NOT_SILVERLIGHT
#endif

[Conditional("NOT_SILVERLIGHT")]
private void DoStuffThatSilverlightCant() {...}

What could be done however, is to have a build configuration for whatever platform you are using that will /define the needed symbol (NOT_SILVERLIGHT in that case).

Coincoin
That will only work in the file in which you declare the method. It's not a global solution
JaredPar
That is a pretty good idea, though. That certainly didn't occur to me.
MojoFilter
@Jared: I stand corrected. I though the only place the define needed to be was with the function declaration and the calls would be optimized out. I usually only use the ConditionalAttribute with /define.
Coincoin