Formula.cs 904 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Concurrent;
  3. using FormulaEnginePoC.FormulaEngine.Mapping;
  4. namespace FormulaEnginePoC.FormulaEngine
  5. {
  6. public abstract class Formula
  7. {
  8. private static readonly ConcurrentDictionary<Type, TypeMapping> CachedTypeMapping = new ConcurrentDictionary<Type, TypeMapping>();
  9. public string UserExpression { get; }
  10. public string CodeExpression { get; }
  11. public Formula(string userExpression, Type mappingType)
  12. {
  13. if (false == CachedTypeMapping.TryGetValue(mappingType, out var mapping))
  14. {
  15. mapping = new TypeMapping(mappingType);
  16. CachedTypeMapping[mappingType] = mapping;
  17. }
  18. UserExpression = userExpression;
  19. CodeExpression = FormulaConverter.Convert(UserExpression, mapping);
  20. }
  21. public abstract void Compile();
  22. }
  23. }