Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compilation for .NET 4 [duplicate]

Possible Duplicate:
Conditional compilation and framework targets

I have some code that works in .NET 4, but it does not work in .NET 3.5. In .NET 3.5 it requires to use interop calls to Windows.

I would like using a "ifdef" to use a different code path in both cases (eventually I will deprecate the .NET 3.5 code).

Is there a pre-defined directive value to identify when the code is compiled with .NET 4?

Is there a good link with all the predefined directives (DEBUG, TRACE, etc.)? The page below only gives the directives, but not the standard predefined values:

C# Preprocessor Directives

like image 918
MMind Avatar asked Feb 03 '11 18:02

MMind


People also ask

What is conditional compilation in C#?

Conditional compilation can be useful when compiling code for a debug build or when compiling for a specific configuration. A conditional directive beginning with an #if directive must explicitly be terminated with an #endif directive. #define lets you define a symbol.

What statements are used for conditional compilation?

The $ELSE statement is used in conjunction with the $IF statement to control conditional compilation. The $END statement is used in conjunction with the $IF statement to control conditional compilation. A $IF statement provides the means whereby selected parts of the source text are not included in the compilation.

How use #define in C#?

The #define directive cannot be used to declare constant values as is typically done in C and C++. Constants in C# are best defined as static members of a class or struct. If you have several such constants, consider creating a separate "Constants" class to hold them.


1 Answers

I think this is what you are looking for:

#if NET40   
...  
#elif NET35  
...  
#else NET20  
...  
#endif  
like image 117
Chingiz Musayev Avatar answered Sep 28 '22 13:09

Chingiz Musayev