| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using SHJX.Service.Control.MoveTime.Interface;
- namespace SHJX.Service.Control.MoveTime
- {
- public class CalculatorContent
- {
- private static readonly ConcurrentDictionary<string, ICalculator> Calculators = new();
- private static CalculatorContent _content;
- private static readonly object locker = new();
- private CalculatorContent() { }
- public static CalculatorContent Instance
- {
- get
- {
- if (_content is null)
- {
- lock (locker)
- {
- _content = new();
- }
- }
- return _content;
- }
- }
- public ICalculator Factory(string step)
- {
- if (Calculators.TryGetValue(step, out ICalculator value)) return value;
- string className = CreatQueryClassName(step);
- try
- {
- ICalculator calculator = Activator.CreateInstance(Type.GetType(className), true) as ICalculator;
- Calculators.TryAdd(step, calculator);
- return calculator;
- }
- catch
- {
- throw new ArgumentNullException(step);
- }
- }
- private string CreatQueryClassName(string step) => $"{GetType().Namespace}.Handler.{step}Calculator";
- }
- }
|