Exemple #1
0
        public static double PerformOperation(double left, double right, MathOperators mathOperator)
        {
            switch (mathOperator)
            {
            case MathOperators.Add: return(left + right);

            case MathOperators.Subtract: return(left - right);

            case MathOperators.Multiply: return(left * right);

            case MathOperators.Divide: return(left / right);

            default: throw new NotImplementedException("How did you even get here???");
            }
        }
Exemple #2
0
        public static string OperatorToString(MathOperators mathOperator)
        {
            switch (mathOperator)
            {
            case MathOperators.Add: return("+");

            case MathOperators.Subtract: return("-");

            case MathOperators.Multiply: return("*");

            case MathOperators.Divide: return("/");

            default: throw new NotImplementedException();
            }
        }
Exemple #3
0
        public static SyntaxKind GetSyntaxKind(MathOperators mathOperator)
        {
            switch (mathOperator)
            {
            case MathOperators.Add:
                return(SyntaxKind.AddExpression);

            case MathOperators.Subtract:
                return(SyntaxKind.SubtractExpression);

            case MathOperators.Divide:
                return(SyntaxKind.DivideExpression);

            case MathOperators.Multiply:
                return(SyntaxKind.MultiplyExpression);

            default:
                throw new ArgumentOutOfRangeException(nameof(mathOperator), mathOperator, null);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MathBinaryExpression"/> class.
        /// </summary>
        /// <param name="leftReference">The left reference.</param>
        /// <param name="rightBinaryExpression">The right other binary expression.</param>
        /// <param name="mathOperator">The math operator to generate.</param>
        /// <param name="useParenthes">If we should generate with paranthes surounding the the binary expression.</param>
        public MathBinaryExpression(
            VariableReference leftReference,
            MathBinaryExpression rightBinaryExpression,
            MathOperators mathOperator,
            bool useParenthes = false)
        {
            if (leftReference == null)
            {
                throw new ArgumentNullException(nameof(leftReference));
            }

            if (rightBinaryExpression == null)
            {
                throw new ArgumentNullException(nameof(rightBinaryExpression));
            }

            _leftExpression  = ReferenceGenerator.Create(leftReference);
            _rightExpression = rightBinaryExpression.GetBinaryExpression();
            _mathOperator    = mathOperator;
            _useParenthes    = useParenthes;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MathBinaryExpression"/> class.
        /// </summary>
        /// <param name="leftExpression">The left expression.</param>
        /// <param name="rigthExpression">The right expression.</param>
        /// <param name="mathOperator">The math operator to generate.</param>
        /// <param name="useParenthes">If we should generate with paranthes surounding the the binary expression.</param>
        public MathBinaryExpression(
            ExpressionSyntax leftExpression,
            ExpressionSyntax rigthExpression,
            MathOperators mathOperator,
            bool useParenthes = false)
        {
            if (leftExpression == null)
            {
                throw new ArgumentNullException(nameof(leftExpression));
            }

            if (rigthExpression == null)
            {
                throw new ArgumentNullException(nameof(rigthExpression));
            }

            _leftExpression  = leftExpression;
            _rightExpression = rigthExpression;
            _mathOperator    = mathOperator;
            _useParenthes    = useParenthes;
        }
Exemple #6
0
        public OperatorExpression(string _operator)
        {
            if (string.IsNullOrEmpty(_operator))
            {
                throw new ArgumentNullException("operator");
            }

            switch (_operator)
            {
            case "+":
                base.Evaluate = new MathEvaluate(Add);
                _mathOperator = MathOperators.Add;
                break;

            case "-":
                base.Evaluate = new MathEvaluate(Subtract);
                _mathOperator = MathOperators.Subtract;
                break;

            case "*":
                base.Evaluate = new MathEvaluate(Multiple);
                _mathOperator = MathOperators.Multiple;
                break;

            case "/":
                base.Evaluate = new MathEvaluate(Divide);
                _mathOperator = MathOperators.Divide;
                break;

            case "%":
                base.Evaluate = new MathEvaluate(Modulo);
                _mathOperator = MathOperators.Modulo;
                break;

            default:
                throw new ArgumentException(Resources.InvalidOperator + _operator, "operator");
            }
        }
Exemple #7
0
        public int Calculate(MathOperators operators, string firstValue, string secondValue)
        {
            int.TryParse(firstValue, out int x);
            int.TryParse(secondValue, out int y);

            switch (operators)
            {
            case MathOperators.Add:
                return(x + y);

            case MathOperators.Sub:
                return(x - y);

            case MathOperators.Divide:
                return(y == 0 ? 0 : (int)(x / y));

            case MathOperators.Mutliply:
                return(x * y);

            default:
                throw new ArgumentException($"Operator provided was not implemented");
            }
        }
 public OIDActionValue(OIDRegister sourceNode, MathOperators @operator, ushort value)
 {
     SourceNode = sourceNode ?? throw new ArgumentNullException(nameof(sourceNode));
     Operator   = @operator;
     Value      = value;
 }
Exemple #9
0
 public MathOperator(IValue value, MathOperators mathOperator)
 {
     this.value        = value;
     this.mathOperator = mathOperator;
 }