public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var classMap = SerializerRegistry.GetClassMap(type); //todo: also base types? var fastReflectionClassMap = GetFastReflectionClassMap(type); var propNames = fastReflectionClassMap.PropertyInfos.Keys.ToList(); var instance = fastReflectionClassMap.CreateInstance(Type.EmptyTypes); //Activator.CreateInstance(type); foreach (var propName in propNames) { MemberMap memberMap = classMap?.GetMemberMap(propName); if (memberMap?.Ignored == true) { continue; } var pInfo = fastReflectionClassMap.PropertyInfos[propName]; pInfo.Setter( ref instance, Serializer.DeserializeObject(br, pInfo.PropertyType, settings, memberMap?.Serializer, memberMap?.SerializerArg)); } return(instance); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { if (br.ReadBoolean() == false) //null { return(null); } var nullableUnderlyingType = Nullable.GetUnderlyingType(type); var serializer = SerializerRegistry.GetSerializer(nullableUnderlyingType); return(Serializer.DeserializeObject(br, nullableUnderlyingType, settings, serializer, serializerArg)); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var typedSerializerArg = GetSerializerArg <DateTimeSerializerArg>(type, settings, serializerArg); if (typedSerializerArg != null && typedSerializerArg.TickResolution > 0) { return(br.ReadCompactDateTime(typedSerializerArg.TickResolution)); } return(new DateTime(br.Read7BitLong(), DateTimeKind.Utc)); //todo: compact }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var typedSerializerArg = GetSerializerArg <DateTimeSerializerArg>(type, settings, serializerArg); if (typedSerializerArg != null && typedSerializerArg.TickResolution > 0) { return(new TimeSpan(br.Read7BitLong() * typedSerializerArg.TickResolution)); } return(new TimeSpan(br.Read7BitLong())); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var typedSerializerArg = GetSerializerArg <FloatingPointSerializerArg>(type, settings, serializerArg); if (typedSerializerArg != null) { return(br.ReadCompactDecimal(typedSerializerArg.DecimalDigits)); } return(br.ReadCompactDecimal()); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var props = type.GetProperties(); var args = new object[props.Length]; for (int i = 0; i < props.Length; i++) { args[i] = Serializer.DeserializeObject(br, props[i].PropertyType, settings, null, null); } var instance = Activator.CreateInstance(type, args); return(instance); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var typedSerializerArg = GetSerializerArg <FloatingPointSerializerArg>(type, settings, serializerArg); if (typedSerializerArg != null) { if (typedSerializerArg.DecimalDigits >= 0) { var decValue = br.ReadCompactDecimal(typedSerializerArg.DecimalDigits); return((float)decValue); } } return(br.ReadSingle()); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { int count = br.Read7BitInt(); if (count == -1) { return(null); } var instance = Array.CreateInstance(type.GetElementType(), count); for (int i = 0; i < count; i++) { instance.SetValue(Serializer.DeserializeObject(br, type.GetElementType(), settings, null, null), i); } return(instance); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { int count = br.Read7BitInt(); if (count == -1) { return(null); } var instance = (IList)Activator.CreateInstance(type); Type genericArgtype = type.GetGenericArguments()[0]; for (int i = 0; i < count; i++) { instance.Add(Serializer.DeserializeObject(br, genericArgtype, settings, null, null)); } return(instance); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { int count = br.Read7BitInt(); if (count == -1) { return(null); } var instance = Activator.CreateInstance(type); Type genericArgtype = type.GetGenericArguments()[0]; var method = type.GetMethod("Add"); for (int i = 0; i < count; i++) { method.Invoke( instance, new object[] { Serializer.DeserializeObject(br, genericArgtype, settings, null, null) }); } return(instance); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var classMap = SerializerRegistry.GetClassMap(type); //todo: also base types? var props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public) .OrderBy(x => x.MetadataToken); var instance = Activator.CreateInstance(type); foreach (var prop in props) { MemberMap memberMap = classMap?.GetMemberMap(prop.Name); if (memberMap?.Ignored == true) { continue; } prop.SetValue(instance, Serializer.DeserializeObject(br, prop.PropertyType, settings, memberMap?.Serializer, memberMap?.SerializerArg)); } return(instance); }
public abstract object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg);
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var guidByte = (byte[])Serializer.DeserializeObject(br, typeof(byte[]), settings, null, null); return(new Guid(guidByte)); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { return(br.ReadString()); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { var val = br.Read7BitLong(); return(Convert.ChangeType(val, type)); }
public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg) { int val = (int)br.Read7BitLong(); return(Enum.ToObject(type, val)); }