namespace SHJX.Service.PortClient { public class OptCommand { private static readonly ConcurrentDictionary _commands = new(); public OptCommand() { } public IPortCommand Factory(ArgType way) { if (_commands.TryGetValue(way, out IPortCommand currentclient)) { return currentclient; } IPortCommand port = way switch { ArgType.Move => new MovePortCommand(), ArgType.GoBack => new GoBackPortCommand(), ArgType.Stop => new StopPortCommand(), ArgType.Inversion => new InversionPortCommand(), ArgType.Speed => new SpeedPortCommand(), ArgType.AcSpeed => new AcSpeedPortCommand(), ArgType.DeSpeed => new DeSpeedPortCommand(), ArgType.Open => new OpenPortCommand(), ArgType.Close => new ClosePortCommand(), ArgType.Read => new ReadPortCommand(), ArgType.HeatRead => new HeatingReadPortCommand(), ArgType.Pid => new PidPortCommand(), ArgType.Temp => new TemperaturePortCommand(), ArgType.Humiture => new HumiturePortCommand(), ArgType.Ratio => new RatioPortCommand(), ArgType.Integral => new IntegralPortCommand(), ArgType.Differential => new DifferentialPortCommand(), ArgType.IntegralDeafult => new IntegralDeafultPortCommand(), _ => throw new ArgumentException("未找到对应的枚举") }; _commands.TryAdd(way, port); return port; } } }