SecureDelete.FileSearch.ExpressionEvaluator.EvaluateExpression C# (CSharp) Méthode

EvaluateExpression() public méthode

Evaluates the expression.
public EvaluateExpression ( string expression ) : ExpressionTree
expression string The expression.
Résultat ExpressionTree
        public ExpressionTree EvaluateExpression(string expression)
        {
            // validate parameters
            if(expression == null) {
                throw new ArgumentNullException("expression");
            }

            if(VerifyParantesis(expression) == false) {
                return null;
            }

            ExpressionTree tree;
            int length;

            // return the resulted tree from parsing
            if(ParseExpression(expression, 0, out tree, out length)) {
                return tree;
            }
            else {
                return null;
            }
        }

Usage Example

Exemple #1
0
        private void ParseExpression()
        {
            ExpressionEvaluator evaluator = new ExpressionEvaluator();
            evaluator.Filters = fileFilter;
            fileFilter.ExpressionTree = evaluator.EvaluateExpression(ExpressionText.Text);
            InvalidLabel.Visible = fileFilter.ExpressionTree == null && ExpressionText.Text.Trim() != string.Empty;

            // get the _filter names and update the color
            FilterName[] filterNames = GetFilerNames();
            UpdateTextColor(filterNames);

            // get current word
            string word;
            int start;
            int end;
            List<FilterName> suggestions = new List<FilterName>();

            if(GetCurrentWord(out word, out start, out end)) {
                // match the word with the _filter names
                int length = filterNames.Length;
                for(int i = 0; i < length; i++) {
                    if(filterNames[i].Name == word) {
                        suggestions.Clear();
                        break;
                    }

                    if(filterNames[i].Name.ToLower().Contains(word.ToLower())) {
                        // add the _filter name
                        suggestions.Add(filterNames[i]);
                    }
                }

                // match it with the logical operators
                if(ExpressionEvaluator.AndImplication.ToLower().StartsWith(word.ToLower())) {
                    suggestions.Add(new FilterName(ExpressionEvaluator.AndImplication, true, ExpressionType.Implication));
                }

                if(ExpressionEvaluator.OrImplication.ToLower().StartsWith(word.ToLower())) {
                    suggestions.Add(new FilterName(ExpressionEvaluator.OrImplication, true, ExpressionType.Implication));
                }
            }

            if(suggestions.Count > 0) {
                // show dialog if not already visible
                if(completitionDialog == null) {
                    completitionDialog = new CompletitionDialog();
                }

                // place the dialog
                Point p;
                Rectangle r;

                if(completitionDialog.Visible) {
                    p = ExpressionText.GetPositionFromCharIndex(start);
                    r = ExpressionText.RectangleToScreen(new Rectangle(p.X, p.Y - 2, 10, 10));
                }
                else {
                    p = ExpressionText.GetPositionFromCharIndex(start);
                    r = ExpressionText.RectangleToScreen(new Rectangle(p.X, p.Y - 2, 10, 10));
                }

                // set suggestions and show
                completitionDialog.ParentControl = ExpressionText;
                completitionDialog.ParentBox = this;
                completitionDialog.Suggestions = suggestions;
                completitionDialog.Show();
                completitionDialog.Left = r.X;
                completitionDialog.Top = r.Y - completitionDialog.Height;

                // move focus back on edit box
                ExpressionText.Focus();
            }
            else {
                if(completitionDialog != null) {
                    completitionDialog.Hide();
                }
            }
        }