コード例 #1
0
        static void TestExpression(string expression, int? expected)
        {
            ExpressionValidationResult expressionValidationResult = ExpressionValidator.Validate(expression);

            if (expressionValidationResult.HasValidationErrors)
            {
                System.Console.WriteLine("{0}", expression);
                foreach (string validationError in expressionValidationResult.ValidationErrors)
                {
                    Console.WriteLine(validationError);
                }
            }
            else
            {
                //var expessionElement = ExpressionProcessor.Process(expressionValidationResult.MinifiedExpression);
                var arithmeticExpression = new ArithmeticExpression(expressionValidationResult.MinifiedExpression);

                if (arithmeticExpression.HasValue)
                {
                    var itsValue = arithmeticExpression.ItsValue;
                    string result = (Int32.Parse(itsValue) == expected) ? "Equal" : "NOT Equal";
                    Console.WriteLine("{0} -> {1} {2} {3}", arithmeticExpression.MinifiedExpression, itsValue, result, expected);
                }
                else
                    Console.WriteLine("{0} -> {1} [{2}]", arithmeticExpression.MinifiedExpression, arithmeticExpression.ProcessingException.Message, arithmeticExpression.ProcessingException.InnerException.Message);
            }
        }
コード例 #2
0
        private void OnEvaluate(object sender, EventArgs e)
        {
            string expression = txtExpression.Text;

            if (expression == String.Empty)
            {
                btnReset.PerformClick();
            }
            else
            {
                ArithmeticExpression arithmeticExpression = new ArithmeticExpression(expression);

                if (arithmeticExpression.HasErrors)
                {
                    txtResult.Text = Resources.IntExpression_OnEvaluate_Error_;
                    txtMessages.Text = arithmeticExpression.ErrorMessages;
                }
                else
                {
                    txtResult.Text = arithmeticExpression.Result;
                }
            }
        }