lundi 1 août 2016

Is it possible to make the app settings editable by using reflection to adjust the readonly attribute?

I found the following code to set the readonly attribute to false for the ConfigurationManager.ConnectionStrings property:

    typeof(ConfigurationElementCollection)
        .GetField("bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic)
        .SetValue(ConfigurationManager.ConnectionStrings, false);

Is it possible to apply this to make the AppSettings property also editable?

AppSettings is a NameValueCollection which implements NameObjectCollectionBase which has the IsReadOnly property on it. However if I call GetFields() it returns an empty list.





Aucun commentaire:

Enregistrer un commentaire