示例#1
0
        private static T GetValue(ValueNode <T> valueNode)
        {
            // Get all ValueNode<T> in the leafs :)
            var valueLeafs = valueNode.Descendents();

            return(valueLeafs.First().Value);
        }
示例#2
0
        private T GetValue(ValueNode <T> valueNode)
        {
            // Get all ValueNode<T> in the leafs :)
            // we can't use OfType because we want also the nested leafs
            var set        = new List <ValueNode <T> >();
            var valueLeafs = valueNode.Descendents(node =>
            {
                if (set.Any(cached => cached.Descendents(c => c == node).Any()))
                {
                    return(false);
                }

                set.Add(node);
                return(true);
            });

            var current = default(T);
            var first   = true;

            foreach (var leaf in valueLeafs)
            {
                current = first
                    ? leaf.Value                        // set current to the first value
                    : Accumulator(current, leaf.Value); // accumulate the other values

                first = false;
            }

            if (first) // no iteration happend
            {
                throw new EvaluatorException("The AccumulateRule did not yield any results");
            }

            return(current);
        }
示例#3
0
 /// <summary>
 ///     Return all strong value nodes descendents.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="branch">The branch.</param>
 /// <returns></returns>
 public static IEnumerable <ValueNode <T> > Descendents <T>(this ValueNode <T> branch) =>
 branch.Descendents(node => true);