I am using SerialPort_DataReceived
event in my project. But I want to have different Strategies of receiving data inside the body of this event
.
I have googled and I found that one way is to inject the Func<> to the methods and changing their behaviour (Strategy Pattern).
But is that possible to do the same for evnets like SerialPort_DataReceived
? If yes how can I do that? (without violating the principles)
Edit:
Actually I want to add Func<>
Parameter to the SerialPort_DataReceived
Like this:
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();
}
I want to change the SerialPort_DataReceived
as the following:
private void SerialPort_DataReceived(Func<sth,sth> Strategy,object sender, SerialDataReceivedEventArgs e)
{
throw new NotImplementedException();
}