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.
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 Encode<T>(...) where T : IMessage and then implement encoder/decoder for each type of message and have ResolveEncoder<T> that would pick encoder for wanted message
or
2. Make method that uses any type of message, as long as it implements IMessage, such as Encode(IMessage message), and use System.Reflection to determine everything I need to know about it.
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".
I would be grateful for any personal experiences or links with benchmarks on how performance falls with either of solutions.