Is there a way to create my.settings
variables dynamically?
I want to generate my.settings variables depending on values in my data base so the number my.settings variables need to vary from time to time.
If i had the following values in my database,
0
2
6
13
77
the names of my.settings variables generated will be
My.Settings.M0
My.Settings.M2
My.Settings.M6
My.Settings.M13
My.Settings.M77
So I want to create those variables on the applications first run. Question after getting the numbers from the Database. How to i create those variables with code?
Also is there a way to remove them with code Because when the values of the database changes and the value does not exist, I then need to remove its variable?
Also i would like some suggestions, If this isn't in a good way.
Project Settings don't seem to do well with serializing and saving values beyond the basic types. What you can do is use a User-scoped string-valued setting to store a serialized Dictionary.
For my example, I created a setting named
SerializedKeyPercentDictionary
of Typestring
and ScopeUser
. I am using JSON for my serialization, as it creates a string of smaller length than most other serializations. For this, you will need to add a reference to System.Runtime.Serializations. With this setting and that reference in place, you can then make a global helper class to provide a strongly-typed dictionary for managing your key-to-percent mapping: