I have a collection of stuffs in a generic Dictionary<string, object>().
The key is a string, and I’m attempting to come up with a way to use a hierarchical data structure instead of a string as they key.
So instead of doing this:
object value = myDictionary["App1.Account1.SomeSetting"]; I want to be able to do this:
object value = myDictionary[App1.Account1.SomeSetting]; (notice lack of quotes around the key.
This means the dictionary will become Dictionary<{something}, object>().
What’s the best way to define that {something}? It would be strongly typed and would works like this:
App1 – could be any number of applications
App1 could contain many accounts (App1.Account1)
Accounts can contain many settings (App1.Account1.Setting1)
The {something} data-structure would be hard coded with all possible levels/settings, but I can’t think of what it could be organized like to still work as a key.
EDIT: See my answer below for the solution. Hopefully it helps someone else.
I think I understand what you want: you want your “flat” Dictionary of keys and values to be made accessible via specifying a compiler-checked identifier set that evaluates to the string that is the key of the Dictionary.
Before going down this road, I must ask, why don’t you simply store the values in this hierarchical structure that would produce your keys? If you’re going to go to the trouble of setting this structure up, it seems rather superfluous to do it just to evaluate it into a string key.
Instead, you could have the relatively simple structure:
… and then either define constant App1, App2, etc, or set these classes to be serializable to-from XML, or mapped to an ORM, so they can be saved in some relatively program-agnostic, human-consumable state.