gyu*_*isc 5 .net app-config system.configuration
我创建了一种动态添加SettingsProperty
到.NET app.config
文件的方法.这一切都很好,但是当我下次启动我的应用程序时,我只能看到设计器中创建的属性.如何加载属性运行时?
我创建的代码SettingsProperty
如下所示:
internal void CreateProperty<T>(string propertyName)
{
string providerName = "LocalFileSettingsProvider";
System.Configuration.SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
System.Configuration.UserScopedSettingAttribute attr = new UserScopedSettingAttribute();
attributes.Add(attr.TypeId, attr);
System.Configuration.SettingsProperty prop;
SettingsProvider provider = ApplicationEnvironment.GlobalSettings.Providers[providerName];
prop = new System.Configuration.SettingsProperty(
propertyName,
typeof(T),
provider,
false,
default(T),
System.Configuration.SettingsSerializeAs.String,
attributes,
false,
false
);
ApplicationEnvironment.GlobalSettings.Properties.Add(prop);
ApplicationEnvironment.GlobalSettings.Reload();
}
Run Code Online (Sandbox Code Playgroud)
下次运行时,我要求设置属性,我找不到任何创建的属性.无论我是否致电ApplicationEnvironment.GlobalSettings.Reload();
.