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) { 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; }