Exemplo n.º 1
0
        public override IValue PerformArithmericOperation(InterpretationContext context, IValue left, BinaryExpression.Operator operation, IValue right)
        {
            ListValue retVal = null;

            switch (operation)
            {
                case BinaryExpression.Operator.Add:
                    Collection leftType = left.Type as Collection;
                    Collection rightType = right.Type as Collection;
                    Collection returnType;

                    if (leftType != null && rightType != null)
                    {
                        if (leftType is GenericCollection)
                        {
                            if (rightType is GenericCollection)
                            {
                                returnType = new GenericCollection(EFSSystem);
                            }
                            else
                            {
                                returnType = rightType;
                            }
                        }
                        else
                        {
                            if (leftType == rightType || rightType is GenericCollection)
                            {
                                returnType = leftType;
                            }
                            else if (leftType.Type == rightType.Type)
                            {
                                returnType = leftType;
                            }
                            else
                            {
                                throw new Exception("Cannot determine the collection type for expression");
                            }
                        }

                        ListValue leftValue = left as ListValue;
                        ListValue rightValue = right as ListValue;
                        if (leftValue != null && rightValue != null)
                        {
                            retVal = new ListValue(returnType, new List<IValue>());
                            foreach (IValue val in leftValue.Val)
                            {
                                if (!(val is EmptyValue))
                                {
                                    retVal.Val.Add(val.RightSide(null, true, true));
                                }
                            }
                            foreach (IValue val in rightValue.Val)
                            {
                                if (!(val is EmptyValue))
                                {
                                    retVal.Val.Add(val.RightSide(null, true, true));
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("Cannot add a collection to a single element");
                        }
                    }
                    break;
            }

            return retVal;
        }
Exemplo n.º 2
0
        public override IValue PerformArithmericOperation(InterpretationContext context, IValue left, BinaryExpression.Operator operation, IValue right)
        {
            ListValue retVal = null;

            switch (operation)
            {
            case BinaryExpression.Operator.Add:
                Collection leftType  = left.Type as Collection;
                Collection rightType = right.Type as Collection;
                Collection returnType;

                if (leftType != null && rightType != null)
                {
                    if (leftType is GenericCollection)
                    {
                        if (rightType is GenericCollection)
                        {
                            returnType = new GenericCollection(EFSSystem);
                        }
                        else
                        {
                            returnType = rightType;
                        }
                    }
                    else
                    {
                        if (leftType == rightType)
                        {
                            returnType = leftType;
                        }
                        else if (leftType.Type == rightType.Type)
                        {
                            returnType = leftType;
                        }
                        else
                        {
                            throw new Exception("Cannot determine the collection type for expression");
                        }
                    }

                    ListValue leftValue  = left as ListValue;
                    ListValue rightValue = right as ListValue;
                    if (leftValue != null && rightValue != null)
                    {
                        retVal = new ListValue(returnType, new List <IValue>());
                        foreach (IValue val in leftValue.Val)
                        {
                            if (!(val is EmptyValue))
                            {
                                retVal.Val.Add(val.RightSide(null, true, true));
                            }
                        }
                        foreach (IValue val in rightValue.Val)
                        {
                            if (!(val is EmptyValue))
                            {
                                retVal.Val.Add(val.RightSide(null, true, true));
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Cannot add a collection to a single element");
                    }
                }
                break;
            }

            return(retVal);
        }