I am writing a prototype TCP connection, and I am having problems homogenizing the data being sent.
At the moment I am sending only strings, but in the future we want to send any object.
At the moment, the code is pretty simple, because I thought everything could be passed to an array of bytes:
void SendData(object headerObject, object bodyObject) { byte[] header = (byte[])headerObject;
This, of course, is easy enough to solve with
if( state.headerObject is System.String ){...}
The problem is that if I do this like that, I need to check the type of EVERY type that cannot be executed for byte [] at runtime.
Since I do not know every object that cannot be executed in byte [] at runtime, this is really not an option.
How to convert any object in general to an array of bytes in C # .NET 4.0?
Steve H. Feb 01 '11 at 16:23 2011-02-01 16:23
source share