Ejemplo n.º 1
0
 public static object Deserialize(byte[] data, Type t)
 {
     if (t == null)
     {
         return(null);
     }
     if (((data != null) ? data.Length : 0) != 0)
     {
         if (t.IsEnum)
         {
             return(Enum.ToObject(t, BloxSerializer.ToInt(data)));
         }
         if (t.IsArray)
         {
             return(BloxSerializer.DeserializeArray(data, t));
         }
         if (t.IsGenericType)
         {
             if (t.GetGenericTypeDefinition() == typeof(List <>))
             {
                 return(BloxSerializer.DeserializeList(data, t));
             }
             return(new byte[0]);
         }
         if (BloxSerializer.readers.ContainsKey(t))
         {
             return(BloxSerializer.readers[t](data));
         }
         return(null);
     }
     return(BloxMemberInfo.GetDefaultValue(t));
 }
Ejemplo n.º 2
0
 static BloxSerializer()
 {
     BloxSerializer.writers = new Dictionary <Type, Func <object, byte[]> >();
     BloxSerializer.readers = new Dictionary <Type, Func <byte[], object> >();
     BloxSerializer.writers[typeof(bool)]       = ((object value) => BloxSerializer.GetBytes((bool)value));
     BloxSerializer.writers[typeof(byte)]       = ((object value) => BloxSerializer.GetBytes((byte)value));
     BloxSerializer.writers[typeof(sbyte)]      = ((object value) => BloxSerializer.GetBytes((sbyte)value));
     BloxSerializer.writers[typeof(char)]       = ((object value) => BloxSerializer.GetBytes((char)value));
     BloxSerializer.writers[typeof(int)]        = ((object value) => BloxSerializer.GetBytes((int)value));
     BloxSerializer.writers[typeof(uint)]       = ((object value) => BloxSerializer.GetBytes((uint)value));
     BloxSerializer.writers[typeof(short)]      = ((object value) => BloxSerializer.GetBytes((short)value));
     BloxSerializer.writers[typeof(ushort)]     = ((object value) => BloxSerializer.GetBytes((ushort)value));
     BloxSerializer.writers[typeof(long)]       = ((object value) => BloxSerializer.GetBytes((long)value));
     BloxSerializer.writers[typeof(ulong)]      = ((object value) => BloxSerializer.GetBytes((ulong)value));
     BloxSerializer.writers[typeof(float)]      = ((object value) => BloxSerializer.GetBytes((float)value));
     BloxSerializer.writers[typeof(double)]     = ((object value) => BloxSerializer.GetBytes((double)value));
     BloxSerializer.writers[typeof(decimal)]    = ((object value) => BloxSerializer.GetBytes((decimal)value));
     BloxSerializer.writers[typeof(string)]     = ((object value) => BloxSerializer.GetBytes((string)value));
     BloxSerializer.writers[typeof(Vector2)]    = ((object value) => BloxSerializer.GetBytes((Vector2)value));
     BloxSerializer.writers[typeof(Vector3)]    = ((object value) => BloxSerializer.GetBytes((Vector3)value));
     BloxSerializer.writers[typeof(Vector4)]    = ((object value) => BloxSerializer.GetBytes((Vector4)value));
     BloxSerializer.writers[typeof(Quaternion)] = ((object value) => BloxSerializer.GetBytes((Quaternion)value));
     BloxSerializer.writers[typeof(Rect)]       = ((object value) => BloxSerializer.GetBytes((Rect)value));
     BloxSerializer.writers[typeof(Color)]      = ((object value) => BloxSerializer.GetBytes((Color)value));
     BloxSerializer.writers[typeof(Color32)]    = ((object value) => BloxSerializer.GetBytes((Color32)value));
     BloxSerializer.readers[typeof(bool)]       = ((byte[] data) => BloxSerializer.ToBool(data));
     BloxSerializer.readers[typeof(byte)]       = ((byte[] data) => BloxSerializer.ToByte(data));
     BloxSerializer.readers[typeof(sbyte)]      = ((byte[] data) => BloxSerializer.ToSByte(data));
     BloxSerializer.readers[typeof(char)]       = ((byte[] data) => BloxSerializer.ToChar(data));
     BloxSerializer.readers[typeof(int)]        = ((byte[] data) => BloxSerializer.ToInt(data));
     BloxSerializer.readers[typeof(uint)]       = ((byte[] data) => BloxSerializer.ToUInt(data));
     BloxSerializer.readers[typeof(short)]      = ((byte[] data) => BloxSerializer.ToShort(data));
     BloxSerializer.readers[typeof(ushort)]     = ((byte[] data) => BloxSerializer.ToUShort(data));
     BloxSerializer.readers[typeof(long)]       = ((byte[] data) => BloxSerializer.ToLong(data));
     BloxSerializer.readers[typeof(ulong)]      = ((byte[] data) => BloxSerializer.ToULong(data));
     BloxSerializer.readers[typeof(float)]      = ((byte[] data) => BloxSerializer.ToFloat(data));
     BloxSerializer.readers[typeof(double)]     = ((byte[] data) => BloxSerializer.ToDouble(data));
     BloxSerializer.readers[typeof(decimal)]    = ((byte[] data) => BloxSerializer.ToDecimal(data));
     BloxSerializer.readers[typeof(string)]     = ((byte[] data) => BloxSerializer.ToString(data));
     BloxSerializer.readers[typeof(Vector2)]    = ((byte[] data) => BloxSerializer.ToVector2(data));
     BloxSerializer.readers[typeof(Vector3)]    = ((byte[] data) => BloxSerializer.ToVector3(data));
     BloxSerializer.readers[typeof(Vector4)]    = ((byte[] data) => BloxSerializer.ToVector4(data));
     BloxSerializer.readers[typeof(Quaternion)] = ((byte[] data) => BloxSerializer.ToQuaternion(data));
     BloxSerializer.readers[typeof(Rect)]       = ((byte[] data) => BloxSerializer.ToRect(data));
     BloxSerializer.readers[typeof(Color)]      = ((byte[] data) => BloxSerializer.ToColor(data));
     BloxSerializer.readers[typeof(Color32)]    = ((byte[] data) => BloxSerializer.ToColor32(data));
 }