title: How to propagate and customise events to other classes?
body: <p>I have a SerialPortWrapper class that deals with the <code>System.IO.Ports.SerialPort</code>, which includes the <code>OnSerialDataRecevied</code> event handler. The following is an outline of the class, and it works:</p>
  
  <pre><code>public class SerialPortWrapper : ISerialPortWrapper
  {
      public event SerialDataReceivedEventHandler DataReceviedHandler;    
  
      private readonly SerialPort _serialPort;
  
      public SerialPortWrapper()
      {
          this._serialPort = new SerialPort
          {
              // configure SerialPort
          };
  
          this._serialPort.DataReceived += DataReceviedHandler;
          this._serialPort.DataReceived += OnSerialDataRecevied;
      }
  
      public void Write(byte[] bytes, int offset, int count)
      {
          this._serialPort.Write(bytes, offset, count);
      }
  
      public void OnSerialDataRecevied(object sender, SerialDataReceivedEventArgs e)
      {
          SerialPort sp = (SerialPort)sender;
          var bytes = new UTF8Encoding().GetBytes(sp.ReadExisting());
      }
  }
  </code></pre>
  
  <p>I also have a class that uses the SerialPortWrapper. I would like an event to fire in this class when <code>OnSerialDataRecevied</code> fires. Preferably, this event object would contain custom data that a <code>SecurityPanel</code> would be concerned with, rather than <code>SerialPort</code> data</p>
  
  <p>You can see in the code below that I tried to add <code>SecurityDataRecevied</code> as a handler for the SerialPortWrapper's <code>DataReceviedHandler</code> but that doesn't work.</p>
  
  <pre><code>public class SecurityPanel : ISecurityPanel
  {
      private readonly ISerialPortWrapper _serialPortWrapper;
  
      public SecurityPanel(ISerialPortWrapper serialPortWrapper)
      {
          _serialPortWrapper = serialPortWrapper;
  
          _serialPortWrapper.DataReceviedHandler += SecurityDataRecevied;
      }
  
      private void SecurityDataRecevied(object sender, SerialDataReceivedEventArgs e)
      {
          // this doens't fire. Prefereably it would have a custom EventArgs object, 
          // rather than SerialDataReceivedEventArgs 
      }
  
      public byte SendMessage(Message message)
      {
          // get bytes from message and send them to the SerialPort
          _serialPortWrapper.Write(bytes, 0, bytes.Length);            
      }
  }
  </code></pre>
  
  <p>The questions I have are</p>
  
  <ul>
  <li>How can I propagate the event to classes that are using the SerialPortWrapper?</li>
  <li>How can I make these custom events that are relevant to the class they're occurring in?</li>
  </ul>