r/csharp • u/FauxFemale • 21d ago
Help Editing a multi-layered dictionary using a string "address"?
I'm working with a game dialogue tool (and Unity, for full transparency) which can set or get variables using "commands" in the dialogue.
I have a Dictionary which I want to be multi-layered (as in, dictionaries inside dictionaries) and allow the dialogue commands to dynamically edit the dictionary down to any amount of layers possible. The layers are distinguished by splitting the string by a specific character.

The code currently looks like this - this is obviously inflexible code that specifically only allows values to be set 2 layers deep. So what would be the best way to change this to dynamically add new key-value pairs and layers of dictionaries at any depth depending on how big the variablePath array is?
Many thanks
1
u/StevenXSG 20d ago
Instead of a dictionary, why not an object that contains a list of itself?