Exemple #1
0
        /// <summary>
        /// Deserializing binary data to a new instance.
        /// </summary>
        /// <param name="objectData">The binary data.</param>
        /// <typeparam name="T">The object type.</typeparam>
        /// <returns>New instance of the deserialized data.</returns>
        public T Deserialize <T>(Stream objectData)
        {
            var reader = new BinaryReader(objectData, Encoding);

            var type     = typeof(T);
            var typeInfo = BoisTypeCache.GetBasicType(type);

            if (typeInfo.AsRootNeedsCompute)
            {
                var computedType = BoisTypeCache.GetRootTypeComputed(type, true, false);

                return(computedType.InvokeReader <T>(reader, Encoding));
            }
            else
            {
                return((T)PrimitiveReader.ReadRootBasicType(reader, type, typeInfo, Encoding));
            }
        }
Exemple #2
0
        /// <summary>
        /// Deserializing binary data to a new instance.
        /// </summary>
        /// <param name="objectData">The binary data.</param>
        /// <param name="type">The object type.</param>
        /// <returns>New instance of the deserialized data.</returns>
        internal object Deserialize(Stream objectData, Type type)
        {
            var reader = new BinaryReader(objectData, Encoding);

            var typeInfo = BoisTypeCache.GetBasicType(type);

            if (typeInfo.AsRootNeedsCompute)
            {
                var computedType = BoisTypeCache.GetRootTypeComputed(type, true, false);

                // ReSharper disable once PossibleNullReferenceException
                var invokeMethod = typeof(BoisComputedTypeInfo).GetMethod(nameof(BoisComputedTypeInfo.InvokeReader),
                                                                          BindingFlags.Instance | BindingFlags.NonPublic)
                                   .MakeGenericMethod(type);

                return(invokeMethod.Invoke(computedType, new object[] { reader, Encoding }));
            }
            else
            {
                return(PrimitiveReader.ReadRootBasicType(reader, type, typeInfo, Encoding));
            }
        }