Beispiel #1
0
        /// <summary>
        /// Evaluates the operator.
        /// </summary>
        /// <returns>The operator.</returns>
        /// <param name="signature">Signature.</param>
        /// <param name="lhs">Lhs.</param>
        /// <param name="rhs">Rhs.</param>
        new public static GeneticBool EvaluateOperator(OperatorSignature signature, GeneticObject lhs, GeneticObject rhs)
        {
            GeneticObject.ValidateOperatorCall(signature, typeof(GeneticBool), lhs, rhs);

            switch (signature.Value)
            {
            case "<":
                return(GeneticBool.OperatorLessThan((GeneticInt)lhs, (GeneticInt)rhs));

            case ">":
                return(GeneticBool.OperatorGreaterThan((GeneticInt)lhs, (GeneticInt)rhs));

            case "==":
                return(GeneticBool.OperatorEquals(lhs, rhs));

            case "!=":
                return(GeneticBool.OperatorNotEquals(lhs, rhs));

            case "&&":
                return(GeneticBool.OperatorAnd((GeneticBool)lhs, (GeneticBool)rhs));

            case "||":
                return(GeneticBool.OperatorAnd((GeneticBool)lhs, (GeneticBool)rhs));
            }

            throw new InvalidOperationException(string.Format(
                                                    "Did not recognize operator with signature {0} with return type {1}",
                                                    signature.Value,
                                                    signature.ReturnType));
        }
Beispiel #2
0
        /// <summary>
        /// Evaluates the operator.
        /// </summary>
        /// <returns>The operator.</returns>
        /// <param name="signature">Signature.</param>
        /// <param name="lhs">Lhs.</param>
        /// <param name="rhs">Rhs.</param>
        new public static GeneticInt EvaluateOperator(OperatorSignature signature, GeneticObject lhs, GeneticObject rhs)
        {
            GeneticObject.ValidateOperatorCall(signature, typeof(GeneticInt), lhs, rhs);

            switch (signature.Value)
            {
            case "+":
                return(GeneticInt.OperatorPlus((GeneticInt)lhs, (GeneticInt)rhs));

            case "-":
                return(GeneticInt.OperatorMinus((GeneticInt)lhs, (GeneticInt)rhs));

            case "*":
                return(GeneticInt.OperatorMultiply((GeneticInt)lhs, (GeneticInt)rhs));

            case "/":
                return(GeneticInt.OperatorDivide((GeneticInt)lhs, (GeneticInt)rhs));
            }

            throw new InvalidOperationException(string.Format(
                                                    "Did not recognize operator with signature {0} with return type {1}",
                                                    signature.Value,
                                                    signature.ReturnType));
        }