Click here to Skip to main content
12,820,077 members (23,663 online)
Click here to Skip to main content


17 bookmarked
Posted 1 Oct 2010

Expression Control for TFS Work Items

, 5 Oct 2010 CPOL
Custom control for TFS Work Items that shows the result of calculating an expression based on the work item fields contents
using System;
using System.Collections;
using System.Text;
using Antlr.Runtime.Tree;
using Evaluant.Calculator.Domain;
using Antlr.Runtime;

namespace Evaluant.Calculator
    public class Expression
        protected string expression;

        public Expression(string expression)
            if (expression == null || expression == String.Empty)
                throw new 
                    ArgumentException("Expression can't be empty", "expression");

            this.expression = expression;

        protected CommonTree Parse(string expression)
            ECalcLexer lexer = new ECalcLexer(new ANTLRStringStream(expression));
            ECalcParser parser = new ECalcParser(new CommonTokenStream(lexer));

                RuleReturnScope rule = parser.expression();
                if (parser.HasError)
                    throw new EvaluationException(parser.ErrorMessage + " " + parser.ErrorPosition);

                return rule.Tree as CommonTree;
            catch (EvaluationException)
            catch (Exception e)
                throw new EvaluationException(e.Message, e);

        public object Evaluate()
            EvaluationVisitor visitor = new EvaluationVisitor();
            visitor.EvaluateFunction += EvaluateFunction;
            visitor.EvaluateParameter += EvaluateParameter;
            visitor.Parameters = parameters;

            return visitor.Result;

        public event EvaluateFunctionHandler EvaluateFunction;
        public event EvaluateParameterHandler EvaluateParameter;

        private Hashtable parameters = new Hashtable();

        public Hashtable Parameters
            get { return parameters; }
            set { parameters = value; }


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer SunHotels
Spain Spain
Under the secret identity of a C# programmer, a freaky guy who loves MSX computers and japanese culture is hidden. Beware!

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 6 Oct 2010
Article Copyright 2010 by konamiman.MSX
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid