string foodType = ConfigurationSettings.AppSettings["No1"];
instance = (Builder)Assembly.Load("创建者模式").CreateInstance("创建者模式." + foodType);
培植文件如下:
<?xml version="1.0" encoding="utf-8" ?><configuration>
<appSettings>
<add key="No1" value="GoldBuilder"/>
<add key="No2" value="NormalBuilder"/>
</appSettings>
</configuration>
每次用都要琢磨半天,所以就记下来了。
string foodType = ConfigurationSettings.AppSettings["No1"];//这一句 代码,会提示已过时。解决方法如下:
1,引用System.Configuration
2,然后将上面代码替换为:
string foodType = System.Configuration.ConfigurationManager.AppSettings["No" + No];