473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Conditional compilation Constant for CLR version

RC
Is there a built-in constant that I can use in a #if statement to
conditonally compile a line of code based on the CLR/Compiler version
e.g. something like:

#if (CLRV2)
string Foo =
System.Configuration.ConfigurationManager.AppSetti ngs("..
#else
string Foo =
System.Configuration.ConfigurationSettings.AppSett ings("...

Dec 14 '06 #1
1 1764
#if statements are processed before compilation, and long before your
code is actually run (which is when you will get to find out which
version of the CLR is present).

It is possible to check CLR version at runtime using
System.Environment.Version, and you could possibly use this to
conditionally select code at runtime. Something like

(untested)

ISettings settings;
if (Environment.Version.Major >= 2)
settings = (ISettings) new SettingsV2(); //access settings through
ConfigurationManager
else
settings = (ISettings) new SettingsV1(); //access settings through
ConfigurationSettings
settings.doSomething();

Dec 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Victor Irzak | last post by:
Hello, I want to build two assemblies that use common c# code. I wish to use preprocessor. I defined a constant YABA in "Conditional compilation constants" in the property pages. So the line...
11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
13
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
34
by: BQ | last post by:
Hello Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20. I would like that at compile time, not at run time. ...
1
by: lavu | last post by:
Is there any way to specify a different executable name for my project based on value that I have set in my conditional compilation constant. For eg: If I have FIRST specified in my conditional...
4
by: Bob | last post by:
Hi, In VS2003 conditional compilation constants and their state could be defined at project level. I was using this to control what features where offered by various builds. i.e....
10
by: Dave | last post by:
I'm a C++ programmer of many years, trying to get my feet wet in C#. I have a question about conditional compilation. In C++, I would sometimes define a constant in an include file, and then...
3
by: ezmeralda | last post by:
Hello, I have some code which shall be compiled in .NET v1.1 and v2.0 but which has to be different for the two .NET-Versions. Therefore I need to use a construct like #if NET_20 <2.0...
1
by: Sagaert Johan | last post by:
Hi Is there a constant i could use to force conditional compilation based on whether i compile for CF or the Full NET framework ? Johan
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.