示例#1
0
 private void ValueEnumerationHelper(ValueEnumerationDelegate callback, ValueNode <T> node, int[] indices, object state)
 {
     if (node.HasChildren)
     {
         int[] childIndices;
         for (int i = 0; i < node.Children.Count; i++)
         {
             childIndices = new int[indices.Length + 1];
             Array.Copy(indices, childIndices, indices.Length);
             childIndices[indices.Length] = i;
             ValueEnumerationHelper(callback, node.Children[i], childIndices, state);
         }
     }
     else if (indices.Length == Depth)
     {
         // do callback and fall out of recursion
         callback(state, indices);
     }
 }
示例#2
0
 public override void EnumerateValues(object state, ValueEnumerationDelegate callback)
 {
     ValueEnumerationHelper(callback, _value, RepeatIndices.Empty, state);
 }
示例#3
0
 /// <summary>
 /// EnumerateValues uses the Visitor design pattern to enumerate all the values associated with this answer.
 /// For each value that is part of the answer, the supplied state object is passed to the supplied callback
 /// method, along with the repeat indices for that value.  The callback must be a delegate of type ValueEnumerationDelegate.
 /// </summary>
 /// <param name="state">An object to keep track of whatever state you will need during the enumeration.
 /// For simple enumerations, passing a reference to the Answer object in question
 /// (so you can use the repeat indices to look up values) may be adequate.</param>
 /// <param name="callback">A delegate of type ValueEnumerationDelegate.</param>
 public abstract void EnumerateValues(object state, ValueEnumerationDelegate callback);