开发者

Writing a cross framework class, ConfigurationManager and ConfigurationSettings

开发者 https://www.devze.com 2022-12-20 05:48 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消