title: C# Binary Serialization
body: <p>I am trying to serialize and deserialize objects to/from a Byte array for network communication, I currently have an interface 'ISerialize'. However I got thinking there should be a more robust way to do this via reflection.</p>
  
  <p>I've looked around a little bit at doing this using BinaryFormater, but I can't see if it will give me the control I require.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I would like to beable to decorate a class as Follows
  (Where fields can be any type so long as they are a system type or are also [Serializable])</p>
  
  <pre><code>[Serializable]
  public class MyClass {
  
      [NonSerialized]
      SomeOtherClass _classFeild;
  
      [Position (0)]
      UInt16 _field1;
  
      [Position (14)]
      UInt32 _feild2;
  
      //..........
  }
  </code></pre>
  
  <p>And have the following functionality,</p>
  
  <pre><code>void Test () {
      MyObject = new MyClass ();
      Byte[] raw;
      raw  =  Serializer.Serialize (MyClass); // Results in _field1 at raw[0,1]
                                              //            _field2 at raw[14-18]
  
      MyClass Deserialized  = Serializer.Deserialize&lt;MyClass&gt; (raw); 
  }
  </code></pre>
  
  <p>where all fields are swapped to / from network order (bigendian)</p>
  
  <hr>
  
  <p>I would also rather white list fields to be serialized rather than blacklist those not to be. So the question is, is can I do this using the Framework, or do I need to write my own implementation?</p>