public override object Read(BinaryReader buffer, Type resultType, TypeDescription typeDescriptor, byte code, BinaryJSONReader binaryJsonReader)
 {
     var count = buffer.ReadInt32();
     object result = resultType != null ? Activator.CreateInstance(resultType, count) : null;
     var array = result as Array;
     var collection = result as IList;
     Type elemenType = resultType != null ? resultType.GetElementType() : null;
     if (elemenType == null && resultType != null)
     {
         elemenType = resultType.GetGenericArguments()[0];
     }
     for (int i = 0; i < count; i++)
     {
         var current = binaryJsonReader.Read(elemenType, buffer);
         if (array != null)
         {
             array.SetValue(current, i);
         }
         else if (collection != null)
         {
             collection.Add(current);
         }
     }
     return result;
 }
 public override object Read(BinaryReader buffer, Type resultType, TypeDescription typeDescriptor, byte code,
     BinaryJSONReader binaryJsonReader)
 {
     var value = binaryJsonReader.Read(Enum.GetUnderlyingType(resultType), buffer);
     var result = Enum.ToObject(resultType, value);
     return result;
 }
 public override object Read(BinaryReader buffer, Type resultType, TypeDescription typeDescriptor, byte code, BinaryJSONReader binaryJsonReader)
 {
     var count = buffer.ReadInt32();
     var keyCode = buffer.ReadByte();
     IDictionary result = null;
     Type keyType = null;
     Type valueType = null;
     if (IsValidDictionary(resultType))
     {
         result = (IDictionary)Activator.CreateInstance(resultType);
         var args = resultType.GetGenericArguments();
         keyType = args[0];
         valueType = args[1];
     }
     for (int i = 0; i < count; i++)
     {
         var key = ReadField(buffer, keyCode);
         var value = binaryJsonReader.Read(valueType, buffer);
         if (result != null)
         {
             result.Add(GetKey(key, keyType), GetValue(value, valueType));
         }
     }
     return result;
 }
 public override object Read(BinaryReader buffer, Type resultType, TypeDescription typeDescriptor, byte code, BinaryJSONReader binaryJsonReader)
 {
     switch (code)
     {
         case BinaryValue.BYTE:
             return Convert.ChangeType(buffer.ReadByte(), resultType);
         case BinaryValue.SBYTE:
             return Convert.ChangeType(buffer.ReadSByte(), resultType);
         case BinaryValue.INT16:
             return Convert.ChangeType(buffer.ReadInt16(), resultType);
         case BinaryValue.UINT16:
             return Convert.ChangeType(buffer.ReadUInt16(), resultType);
         case BinaryValue.INT32:
             return Convert.ChangeType(buffer.ReadInt32(), resultType);
         case BinaryValue.UINT32:
             return Convert.ChangeType(buffer.ReadUInt32(), resultType);
         case BinaryValue.INT64:
             return Convert.ChangeType(buffer.ReadInt64(), resultType);
         case BinaryValue.UINT64:
             return Convert.ChangeType(buffer.ReadUInt64(), resultType);
         case BinaryValue.FLOAT:
             return Convert.ChangeType(buffer.ReadSingle(), resultType);
         case BinaryValue.BOOLEAN:
             return Convert.ChangeType(buffer.ReadBoolean(), resultType);
         case BinaryValue.DOUBLE:
             return Convert.ChangeType(buffer.ReadDouble(), resultType);
         case BinaryValue.DECIMAL:
             return Convert.ChangeType(buffer.ReadDecimal(), resultType);
         case BinaryValue.CHAR:
             return Convert.ChangeType(buffer.ReadChar(), resultType);
     }
     return null;
 }
 public override object Read(BinaryReader buffer, Type resultType, TypeDescription typeDescriptor, byte code, BinaryJSONReader binaryJsonReader)
 {
     var count = buffer.ReadInt32();
     object result = resultType != null? Activator.CreateInstance(resultType) : null;
     for (int i = 0; i < count; i++)
     {
         var fieldName = ReadField(buffer);
         var info = typeDescriptor.GetType(resultType);
         var field = info.GetField(fieldName);
         Type type = field != null ? field.FieldType : null;
         var value = binaryJsonReader.Read(type, buffer);
         if (field != null)
         {
             info.SetValue(fieldName, result, value);
         }
     }
     return result;
 }
 public override object Read(BinaryReader buffer, Type resultType, TypeDescription typeDescriptor, byte code, BinaryJSONReader binaryJsonReader)
 {
     return null;
 }
 public override object Read(BinaryReader buffer, Type resultType, TypeDescription typeDescriptor, byte code, BinaryJSONReader binaryJsonReader)
 {
     var count = buffer.ReadInt32();
     var bytes = buffer.ReadBytes(count);
     return Encoding.UTF8.GetString(bytes);
 }