12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- using System.Collections.Generic;
- namespace NTERA.Interpreter
- {
- public class VariableDictionary : Dictionary<string, Dictionary<int, Value>>
- {
- public VariableDictionary() : base(StringComparer.InvariantCultureIgnoreCase)
- {
- InitDefaults();
- }
- public new Value this[string key]
- {
- get => this[key, 0];
- set => this[key, 0] = value;
- }
- public Value this[string key, int arrayIndex]
- {
- get => base[key][arrayIndex];
- set
- {
- if (base.TryGetValue(key, out var dict))
- dict[arrayIndex] = value;
- else
- Add(key, arrayIndex, value);
- }
- }
- public void Add(string key, Value value)
- {
- Add(key, 0, value);
- }
- public void Add(string key, int arrayIndex, Value value)
- {
- base.Add(key, new Dictionary<int, Value>
- {
- [arrayIndex] = value
- });
- }
- private void InitDefaults()
- {
- Add("LOCAL", 0);
- Add("LOCALS", "");
- Add("RESULT", 0);
- Add("RESULTS", "");
- }
- }
- }
|