我SerialPort_DataReceived
在我的项目中使用事件。但是我想在 this 的主体内有不同的接收数据的策略event
。
我用谷歌搜索,发现一种方法是将 Func<> 注入方法并改变它们的行为(策略模式)。
但是对于像这样的 evnets 是否可以这样做SerialPort_DataReceived
?如果是,我该怎么做?(不违反原则)
编辑:
实际上我想将Func<>
参数添加到SerialPort_DataReceived
这样的:
public Rs232(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
{
SerialPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits);
SerialPort.DataReceived += SerialPort_DataReceived;
}
private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
throw new NotImplementedException();
}
我想更改SerialPort_DataReceived
如下:
private void SerialPort_DataReceived(Func<sth,sth> Strategy,object sender, SerialDataReceivedEventArgs e)
{
throw new NotImplementedException();
}