Example #1
0
        protected RCBlock RecursiveWhere(RCBlock left, RCBlock right)
        {
            if (left.Count != right.Count)
            {
                throw new Exception(string.Format(
                                        "Left count was {0} but right count was {1}. Counts must match",
                                        left.Count,
                                        right.Count));
            }
            RCBlock result = RCBlock.Empty;

            for (int i = 0; i < left.Count; ++i)
            {
                RCBlock leftName   = left.GetName(i);
                RCValue rightValue = right.Get(i);
                if (rightValue is RCBlock)
                {
                    RCBlock rightBlock  = (RCBlock)rightValue;
                    RCBlock leftBlock   = left.GetBlock(i);
                    RCBlock childResult = RecursiveWhere(leftBlock, rightBlock);
                    if (childResult.Count > 0)
                    {
                        result = new RCBlock(result, leftName.Name, leftName.Evaluator, childResult);
                    }
                }
                else if (rightValue is RCBoolean)
                {
                    if (rightValue.Count == 1)
                    {
                        if (right.GetBoolean(i))
                        {
                            result = new RCBlock(result, leftName.Name, ":", leftName.Value);
                        }
                    }
                    else
                    {
                        RCBoolean rightVector = (RCBoolean)rightValue;
                        RCBlock   leftBlock   = left.GetBlock(i);
                        RCBlock   childResult = RCBlock.Empty;
                        for (int j = 0; j < rightVector.Count; ++j)
                        {
                            RCBlock leftVar = leftBlock.GetName(j);
                            if (rightVector[j])
                            {
                                childResult = new RCBlock(childResult, leftVar.Name, ":", leftVar.Value);
                            }
                        }
                        if (childResult.Count > 0)
                        {
                            result = new RCBlock(result, leftName.Name, leftName.Evaluator, childResult);
                        }
                    }
                }
            }
            return(result);
        }