示例#1
0
 public TValue this[string key]
 {
     get
     {
         // will throw KeyNotFound exception if not present
         string[] components = key.Split(new char[] { '.' }, 2);
         if (components.Length == 1)
         {
             if (leaves.ContainsKey(key) && hasLeaf(leaves[key]))
             {
                 return(getLeaf(leaves[key]));
             }
             else
             {
                 throw new KeyNotFoundException(key);
             }
         }
         else
         {
             DirectoryHT <TValue> child = children[components[0]];
             return(child[components[1]]);
         }
     }
     set
     {
         Add(key, value);
     }
 }
示例#2
0
 public DirectoryHT(DirectoryHT <TValue> p)
 {
     parent = p;
     if (p != null)
     {
         Default = p.Default;
         Alts    = p.Alts;
     }
 }
示例#3
0
 // p is key to a sub directory
 public DirectoryHT <TValue> subDir(string p)
 {
     string[] components = p.Split(new char[] { '.' }, 2);
     if (components.Length == 1)
     {
         return(children[components[0]]);
     }
     else
     {
         DirectoryHT <TValue> child = children[components[0]];
         return(child == null ? null : child.subDir(components[1]));
     }
 }
示例#4
0
 public void Add(string key, TValue value, string variant)
 {
     string[] components = key.Split(new char[] { '.' }, 2);
     if (components.Length == 1)
     {
         if (!leaves.ContainsKey(components[0]))
         {
             leaves[components[0]] = new Dictionary <string, TValue>();
         }
         leaves[components[0]][variant] = value;
     }
     else
     {
         if (!children.ContainsKey(components[0]))
         {
             children[components[0]] = new DirectoryHT <TValue>(this);
         }
         children[components[0]].Add(components[1], value, variant);
     }
 }