Writing a cross framework class, ConfigurationManager and ConfigurationSettings
I'm trying to write a little web.config reading class, and want it to be available for all .net framework solutions I am writing.
Everything is going fine, except for .net 1.1 and below I need to use System.configuration.configurationsettings.appsettings and for after 1.1 am using System.configuration.configurationmanager.appsettings.
This is a bit frustrating at the minute, and I want to figure out is there a way to do the following pseudo code
if environment.version.major < 2 then
use configurationsettings.appsettings
else
use configurationmanager.appse开发者_如何学编程ttings.
end if
I tried a little of using type.gettype to get around it, but I thought this must be such a simple fix, that someone else has a neat answer.
Can you do it by entering a flag in VS, go to project properties, in build option, conditional compilation symbols which you could enter a value like aspnet11 or aspnet2, and then you can do conditional code in your app like:
#if aspnet11
#elseif aspnet2
#else
#endif
And so you can build multiple versions of your library for multiple frameworks...
HTH.
精彩评论