PC Review


Reply
Thread Tools Rate Thread

Conditional compilation Constant for CLR version

 
 
RC
Guest
Posts: n/a
 
      14th Dec 2006
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.AppSettings("..
#else
string Foo =
System.Configuration.ConfigurationSettings.AppSettings("...

 
Reply With Quote
 
 
 
 
Chris Williamson
Guest
Posts: n/a
 
      14th Dec 2006
#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();

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
predefined constant for conditional compilation based on NETCF or Full framework? Sagaert Johan Microsoft C# .NET 1 24th May 2007 07:33 PM
Conditional Compilation dependent on .net-Version ezmeralda@gmx.de Microsoft C# .NET 3 10th Jan 2007 10:24 PM
RE: Conditional Compilation dependent on .net-Version Michael Nemtsev Microsoft C# .NET 0 10th Jan 2007 09:35 PM
Re: Conditional Compilation using Application.Version Stephen Bullen Microsoft Excel Programming 0 9th Nov 2004 08:48 AM
conditional compilation by framework version Petr Majer Microsoft Dot NET Framework 1 23rd Jul 2003 06:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:31 AM.