72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
|
|
namespace JDSongConverter
|
|
{
|
|
/// <summary>
|
|
/// Singleton, which contains usual standard constants.
|
|
/// </summary>
|
|
public class ConstantDefinitions
|
|
{
|
|
protected static readonly Dictionary<string, string> _definitions;
|
|
|
|
#region Constructor
|
|
|
|
static ConstantDefinitions()
|
|
{
|
|
_definitions = new Dictionary<string, string>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Protected constructor. Use inherited version of this class.
|
|
/// </summary>
|
|
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
|
|
|
|
/// <summary>
|
|
/// Return a clone of the internal constant dictionary.
|
|
/// </summary>
|
|
public Dictionary<string, string> CloneDefinitions()
|
|
{
|
|
return new Dictionary<string, string>(_definitions);
|
|
}
|
|
|
|
#region Protected methods
|
|
|
|
/// <summary>
|
|
/// Add constants to the internal constant dictionary.
|
|
/// </summary>
|
|
protected void InternalAddConstants(IEnumerable<Constant> constants)
|
|
{
|
|
foreach (var constant in constants)
|
|
{
|
|
_definitions[constant.Name] = constant.Value;
|
|
}
|
|
}
|
|
|
|
public string EvaluateExpression(string expression, IDictionary<string, string> definitions = null, bool expandEnvironment = false)
|
|
{
|
|
return JDSongConverter.EvaluateExpression.Do(expression, definitions ?? _definitions, expandEnvironment);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|