using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.RecipeFramework.Library;
using System.ComponentModel.Design;
using Microsoft.Practices.ComponentModel;

namespace Microsoft.Practices.RecipeFramework.Extensions.CommonHelpers
{
    /// <summary>
    /// Helper class to evaluate expressions using <see cref="ExpressionEvaluationService"/>
    /// </summary>
    public static class ExpressionEvaluationHelper
    {
        /// <summary>
        /// Evaluates an expression using <see cref="ExpressionEvaluationService"/>
        /// </summary>
        /// <param name="dictionary">An instance of <see cref="IDictionaryService"/></param>
        /// <param name="expression">Expression to evaluate</param>
        /// <returns>The result as an object</returns>
        public static object EvaluateExpression(IDictionaryService dictionary, string expression)
        {
            ExpressionEvaluationService evaluator = new ExpressionEvaluationService();
            object result = null;
            try
            {
                result = evaluator.Evaluate(expression, new ServiceAdapterDictionary(dictionary));
            }
            catch { }
            return result;
        }
    }
}
