using System; using System.Collections.Concurrent; using FormulaEnginePoC.FormulaEngine.Mapping; namespace FormulaEnginePoC.FormulaEngine { public abstract class Formula { private static readonly ConcurrentDictionary CachedTypeMapping = new ConcurrentDictionary(); public string UserExpression { get; } public string CodeExpression { get; } public Formula(string userExpression, Type mappingType) { if (false == CachedTypeMapping.TryGetValue(mappingType, out var mapping)) { mapping = new TypeMapping(mappingType); CachedTypeMapping[mappingType] = mapping; } UserExpression = userExpression; CodeExpression = FormulaConverter.Convert(UserExpression, mapping); } public abstract void Compile(); } }