Esempio n. 1
0
        public static bool CompareEquality(object a, object b)
        {
            if (a is double || b is double)
            {
                return(ConvertNode.ToDouble(a) == ConvertNode.ToDouble(b));
            }

            if (a == null)
            {
                return(b == null);
            }
            else if (b == null)
            {
                return(false);
            }
            else if (a is bool)
            {
                return((bool)a == ConvertNode.ToBool(b));
            }
            else if (a is int)
            {
                return((int)a == ConvertNode.ToInt(b));
            }
            else if (a is double)
            {
                return((double)a == ConvertNode.ToDouble(b));
            }
            else if (a is char)
            {
                return(a.ToString() == ConvertNode.ToString(b));
            }
            else if (a is string)
            {
                return((string)a == ConvertNode.ToString(b));
            }
            else if (a is char)
            {
                return(a.ToString() == ConvertNode.ToString(b));
            }
            else
            {
                return(a == b);
            }
        }
Esempio n. 2
0
        public override object Get(RuntimeState state, object[] parametersHint)
        {
            // Short-circuit operators

            switch (operation)
            {
            case Operation.And:
            {
                if (!ConvertNode.ToBool(operands[0].Get(state)))
                {
                    return(false);
                }

                return(ConvertNode.ToBool(operands[1].Get(state)));
            }
            }

            // Normal operators

            object[] operandValues = new object[operands.Length];

            for (int n = 0; n < operands.Length; n++)
            {
                operandValues[n] = operands[n].Get(state);
            }

            state.RunningSource = Source;

            switch (operation)
            {
            case Operation.Is:
                return(Is(
                           operandValues[0],
                           (Type)operandValues[1]));

            case Operation.Not:
                return(Not(operandValues[0]));

            case Operation.Add:
                return(Add(
                           operandValues[0],
                           operandValues[1]));

            case Operation.Subtract:
                return(Subtract(
                           operandValues[0],
                           operandValues[1]));

            case Operation.Multiply:
                return(Multiply(
                           operandValues[0],
                           operandValues[1]));

            case Operation.Divide:
                return(Divide(
                           operandValues[0],
                           operandValues[1]));

            case Operation.CompareLess:
                return(CompareLess(
                           operandValues[0],
                           operandValues[1]));

            case Operation.CompareLessOrEqual:
                return(CompareLessOrEqual(
                           operandValues[0],
                           operandValues[1]));

            case Operation.CompareEquality:
                return(CompareEquality(
                           operandValues[0],
                           operandValues[1]));

            case Operation.CompareInequality:
                return(CompareInequality(
                           operandValues[0],
                           operandValues[1]));

            case Operation.CompareGreater:
                return(CompareGreater(
                           operandValues[0],
                           operandValues[1]));

            case Operation.CompareGreaterOrEqual:
                return(CompareGreaterOrEqual(
                           operandValues[0],
                           operandValues[1]));

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 3
0
 public static bool And(object a, object b)
 {
     return(ConvertNode.ToBool(a) && ConvertNode.ToBool(b));
 }