0

WCF Conditional Operations in Service Contract

#if SILVERLIGHT // <------------------------------ ( 1 )
// Silverlight Operations
#else // <------------------------------ ( 2 )
// NON Silverlight Operations
#endif

Mark #1 can be converted to

[Conditional ( "SILVERLIGHT" )]

How to convert Mark #2 ( ELSE Condition [ NON Silverlight ] )

Ahmed Ghoneim
  • 6,834
  • 9
  • 49
  • 79
  • I do not think there is a direct counterpart, and frankly in most cases if you are trying to get one physical file to compile for multiple target platforms, then #if is usually your main option (unless you target the portable class library framework) – Marc Gravell Aug 12 '12 at 22:33

2 Answers2

2

ConditionalAttribute has some restrictions that #if does not have. Namely, the method cannot return anything but void and you cannot provide a negative version.

#if simply omits the code, but Conditional tells the compiler to noop calls to it.

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
2

The ConditionalAttribute is not the same as a C# Preprocessor Directives. So, attempting to replace one with the other is not really appropriate.

See this related answer: https://stackoverflow.com/a/3788719/347172

Community
  • 1
  • 1
myermian
  • 31,823
  • 24
  • 123
  • 215