12345678910111213141516171819202122232425262728 |
- using System;
- using System.Collections.Concurrent;
- using FormulaEnginePoC.FormulaEngine.Mapping;
- namespace FormulaEnginePoC.FormulaEngine
- {
- public abstract class Formula
- {
- private static readonly ConcurrentDictionary<Type, TypeMapping> CachedTypeMapping = new ConcurrentDictionary<Type, TypeMapping>();
- 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();
- }
- }
|