Beispiel #1
0
 public void Deserialize <T>(out T value)
 {
     if (Bit_Conversion <T> .Is_Supported)
     {
         var bytes = stream.Read_Bytes(Bit_Conversion <T> .Bytes_Needed);
         if (swap_endianness)
         {
             Array.Reverse(bytes);
         }
         value = Bit_Conversion <T> .From_Bytes(bytes);
     }
     else
     {
         Linear_Serialization_Helper <T> .Deserialize(this, out value);
     }
 }
Beispiel #2
0
        //NOTE: C# doesn't support template specialization, so to kind of mimick that we:
        //		1) use overloading (meaning even for Deserialize we use out, instead of just returning)
        //		2) use runtime reflection to bind to the given extension method (done only once, using static constructors)
        public void Serialize <T>(T value)
        {
            //primitive types will be handled here...
            if (Bit_Conversion <T> .Is_Supported)
            {
                var bytes = Bit_Conversion <T> .To_Bytes(value);

                if (swap_endianness)
                {
                    Array.Reverse(bytes);
                }
                stream.Write(bytes, 0, bytes.Length);
            }
            else
            {
                //...everything else will go via their extension, and come back to this method for individual fields
                Linear_Serialization_Helper <T> .Serialize(this, value);
            }
        }