private bool ValidateExpression()
        {
            try
            {
                //preverimo z -1 in 1
                Mathematics.MathParser _mathParser;

                _mathParser = new Mathematics.MathParser(new KeyValuePair <string, double>("x", -1));
                _mathParser.Compute(this.customComboBox_Expression.Text);

                _mathParser = new Mathematics.MathParser(new KeyValuePair <string, double>("x", 1));
                _mathParser.Compute(this.customComboBox_Expression.Text);

                this.customComboBox_Expression.BackColor = Defaults.LightGreenColor;

                return(true);
            }
            catch (Exception _exception)
            {
                this.customComboBox_Expression.BackColor = Defaults.LightRedColor;

                Utility.Exception(
                    this,
                    this.Text,
                    _exception);

                return(false);
            }
        }
        private void Form_AddAFunctionReference_Load(object sender, EventArgs e)
        {
            #region "zložimo vse suportane tokene v report"
            Mathematics.MathParser _mathParser = new Mathematics.MathParser();

            List <ReportItem> _reportItems = new List <ReportItem>();

            KeyValuePair <string, string>[] _operators = _mathParser.GetSupportedOperators();
            foreach (KeyValuePair <string, string> _keyValuePair in _operators)
            {
                ReportItem _reportItem = new ReportItem(
                    _keyValuePair.Key,
                    _keyValuePair.Value,
                    "Operators");

                _reportItems.Add(_reportItem);
            }

            KeyValuePair <string, string>[] _functions = _mathParser.GetSupportedFunctions();
            foreach (KeyValuePair <string, string> _keyValuePair in _functions)
            {
                ReportItem _reportItem = new ReportItem(
                    _keyValuePair.Key,
                    _keyValuePair.Value,
                    "Functions");

                _reportItems.Add(_reportItem);
            }

            KeyValuePair <string, string>[] _constants = _mathParser.GetSupportedConstants();
            foreach (KeyValuePair <string, string> _keyValuePair in _constants)
            {
                ReportItem _reportItem = new ReportItem(
                    _keyValuePair.Key,
                    _keyValuePair.Value,
                    "Constants");

                _reportItems.Add(_reportItem);
            }

            ReportItem _reportItemX = new ReportItem(
                "x",
                "The X in the function",
                "Constants");

            _reportItems.Add(_reportItemX);

            this.report1.ReportItems = _reportItems.ToArray();
            #endregion "zložimo vse suportane tokene v report"

            this.customComboBox_Expression.Items.Clear();
            this.customComboBox_Expression.Items.AddRange(FunctionInfoReference.PreviousExpressions);
        }
示例#3
0
        public static void Start()
        {
            string _expression = "2 log(3)";

            try
            {
                Mathematics.MathParser _mathParser = new Mathematics.MathParser();
                double _output = _mathParser.Compute(_expression);
            }
            catch (Exception _ex)
            {
            }
        }