title: System.Reflection vs Generics - performance
body: <p>I'm about to write a set of methods on a server application that take messages received from TCP socket, encode/decode them, and encrypt/decrypt them.</p>
  
  <p>Considering messages are defined as special types, each with its own set of properties and total length, I need to opt for one of the following solutions:
  1. Make methods that use generics, such as <code>Encode&lt;T&gt;(...) where T : IMessage</code> and then implement encoder/decoder for each type of message and have <code>ResolveEncoder&lt;T&gt;</code> that would pick encoder for wanted message
  or
  2. Make method that uses any type of message, as long as it implements <code>IMessage</code>, such as <code>Encode(IMessage message)</code>, and use System.Reflection to determine everything I need to know about it.</p>
  
  <p>I'm more interested in doing solution #2 as it makes my code 30 times smaller. However, I'm worried whether constant reflection of properties will hit the performance. Now as I'm time limited to finish the project, I can't really "experiment".</p>
  
  <p>I would be grateful for any personal experiences or links with benchmarks on how performance falls with either of solutions.</p>