下次如何加载动态创建的设置属性?

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();.

Joe*_*ine 1

用户定义的配置设置与创建它们所用的程序集版本相关联。如果您有滚动版本号(例如 1.0... ,您将丢失上次运行的设置。