Example #1
0
        public static Calculator GetCalculator(OperandPair operandPair)
        {
            var scalarCount  = 0;
            var stringCount  = 0;
            var specialCount = 0;
            var boolCount    = 0;

            if (operandPair.Left is ScalarValue)
            {
                scalarCount++;
            }
            if (operandPair.Left is StringValue)
            {
                stringCount++;
            }
            if (operandPair.Left is ISuffixed)
            {
                specialCount++;
            }
            if (operandPair.Left is BooleanValue)
            {
                boolCount++;
            }
            if (operandPair.Right is ScalarValue)
            {
                scalarCount++;
            }
            if (operandPair.Right is StringValue)
            {
                stringCount++;
            }
            if (operandPair.Right is ISuffixed)
            {
                specialCount++;
            }
            if (operandPair.Right is BooleanValue)
            {
                boolCount++;
            }

            if (scalarCount == 2)
            {
                return(calculatorScalar ?? (calculatorScalar = new CalculatorScalar()));
            }
            if (stringCount > 0)
            {
                return(calculatorString ?? (calculatorString = new CalculatorString()));
            }
            if (boolCount > 0)
            {
                return(calculatorBool ?? (calculatorBool = new CalculatorBool()));
            }
            if (specialCount > 0)
            {
                return(calculatorStructure ?? (calculatorStructure = new CalculatorStructure()));
            }

            throw new NotImplementedException(string.Format("Can't operate types {0} and {1}", operandPair.Left.GetType(), operandPair.Right.GetType()));
        }
Example #2
0
 public void Setup()
 {
     calc = new CalculatorStructure();
 }