J'ai créé un moyen d'ajouter dynamiquement SettingsProperty
à un fichier .NET app.config
. Tout fonctionne bien, mais quand je lance mon application la prochaine fois que je peux seulement voir les propriétés qui sont créées dans le concepteur. Comment puis-je recharger l'exécution des propriétés?Comment recharger une propriété créée dynamiquement la prochaine fois?
Mon code pour créer le SettingsProperty
se présente comme suit:
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();
}
Lorsque la prochaine exécution je demande la propriété des paramètres je ne pouvais pas trouver des propriétés créées previosuly. Peu importe si j'appelle le ApplicationEnvironment.GlobalSettings.Reload();
ou non.