Beispiel #1
0
 /// <summary>
 /// Find a child by its name
 /// </summary>
 /// <param name="dict">accu sets</param>
 /// <param name="name">structured multiple names separated by a dot</param>
 /// <returns>element found</returns>
 public static AccuChild RecursiveFindByName(Dictionary <string, Accu> dict, string name)
 {
     string[] seq = name.Split('.');
     if (seq.Length > 1)
     {
         if (dict.ContainsKey(seq[0]))
         {
             Accu a = dict[seq[0]];
             if (a.Variables.ContainsKey(seq[1]))
             {
                 return(AccuChild.RecursiveFindByName(a.Variables[seq[1]] as AccuChild, 2, seq));
             }
             else
             {
                 throw new KeyNotFoundException(String.Format("{0} not found", seq[1]));
             }
         }
         else
         {
             throw new KeyNotFoundException(String.Format("{0} not found", seq[0]));
         }
     }
     else
     {
         throw new ArgumentException("bad name", "name");
     }
 }
Beispiel #2
0
 /// <summary>
 /// Find a child by its name
 /// </summary>
 /// <param name="types">accu types</param>
 /// <param name="vars">accu variables</param>
 /// <param name="name">structured multiple names separated by a dot</param>
 /// <returns>element found</returns>
 public static AccuChild RecursiveFindByName(Dictionary <string, Accu> types, Dictionary <string, Accu> vars, string name)
 {
     if (name.StartsWith("$"))
     {
         name = name.Substring(1);
         return(Accu.RecursiveFindByName(vars, name));
     }
     else
     {
         return(Accu.RecursiveFindByName(types, name));
     }
 }
Beispiel #3
0
 /// <summary>
 /// Find a child by its name
 /// </summary>
 /// <param name="root">root accu</param>
 /// <param name="index">index position</param>
 /// <param name="seq">sequence name</param>
 /// <returns>element found</returns>
 public static AccuChild RecursiveFindByName(Accu root, int index, string[] seq)
 {
     if (index < seq.Length)
     {
         AccuChild a = root.Values.Last(x => x.Name == seq[index]) as AccuChild;
         return(AccuChild.RecursiveFindByName(a, index + 1, seq));
     }
     else
     {
         throw new FormatException();
     }
 }