using System.Collections.Generic; using System.Windows.Forms; namespace JDSongConverter { /// /// Singleton, which contains usual standard constants. /// public class ConstantDefinitions { protected static readonly Dictionary _definitions; #region Constructor static ConstantDefinitions() { _definitions = new Dictionary(); } /// /// Protected constructor. Use inherited version of this class. /// protected ConstantDefinitions() { _definitions["executablePath"] = Application.ExecutablePath; _definitions["productName"] = Application.ProductName; _definitions["productVersion"] = Application.ProductVersion; _definitions["startupPath"] = Application.StartupPath; _definitions["productName"] = Application.ProductName; _definitions["userAppDataPath"] = Application.UserAppDataPath; _definitions["userAppDataRegistry"] = Application.UserAppDataRegistry.Name; #if RELEASE _definitions["buildConfig"] = "Release"; #else _definitions["buildConfig"] = "Debug"; #endif } #endregion /// /// Return a clone of the internal constant dictionary. /// public Dictionary CloneDefinitions() { return new Dictionary(_definitions); } #region Protected methods /// /// Add constants to the internal constant dictionary. /// protected void InternalAddConstants(IEnumerable constants) { foreach (var constant in constants) { _definitions[constant.Name] = constant.Value; } } public string EvaluateExpression(string expression, IDictionary definitions = null, bool expandEnvironment = false) { return JDSongConverter.EvaluateExpression.Do(expression, definitions ?? _definitions, expandEnvironment); } #endregion } }