コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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
        }
コード例 #4
0
        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()));
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
 public abstract object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg);
コード例 #13
0
        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));
        }
コード例 #14
0
 public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg)
 {
     return(br.ReadString());
 }
コード例 #15
0
        public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg)
        {
            var val = br.Read7BitLong();

            return(Convert.ChangeType(val, type));
        }
コード例 #16
0
        public override object Deserialize(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializerArg serializerArg)
        {
            int val = (int)br.Read7BitLong();

            return(Enum.ToObject(type, val));
        }