title: How to define a static function with a generic return type meant to be overriden
body: <p>I am trying to do something so convoluted it's hurting my brain. So please, if you can think of a better way of doing it than what I'm asking for, I'm all ears!</p>
  
  <p>Essentially I have a class, <code>ClientSession</code>, and this class accepts messages over tcp and exposes them through an <code>OnMessageReceived</code> event. I am trying to tell the <code>ClientSession</code> to parse the message before exposing it in the event using a <code>MessageParser</code> class, passed as a generic parameter. I want to use a static method to avoid instantiating objects for nothing. I also want anyone else to be able to create their own message parser that spits out whatever <code>Type</code> they want. </p>
  
  <p>Essentially, I need to </p>
  
  <ul>
  <li>Guarantee to the <code>ClientSession</code> class that it can call <code>TryParse()</code> on the generic type I pass it during instantiation.</li>
  <li>implement <code>TryParse()</code> as a static method</li>
  </ul>
  
  <p>Like this</p>
  
  <pre><code>public static abstract class MessageParser&lt;TMessage&gt;
  {
      public static abstract TMessage TryParse(byte[] bytes);
  }
  </code></pre>
  
  <p>Then someone else could define their own parser:</p>
  
  <pre><code>public static class ProtoParser : MessageParser&lt;ProtoMessage&gt;
  {
      public static ProtoMessage TryParse(byte[] bytes)
      {
          do some stuff...
          return new ProtoMessage;
      }
  }
  </code></pre>
  
  <p>and finally:</p>
  
  <pre><code>public class ClientSession&lt;TParser&gt;
  {
      public void OnMessageReceived(Object sender, MessageEventArgs e)
      {
          return TParser.TryParse(e.bytes);
      }
  {
  </code></pre>
  
  <p>I know that static and abstract together is impossible, but you get the idea.</p>
  
  <p>I have a gut feeling that I'm just approaching this wrong. Thanks in advance!</p>