Example #1
0
        public static object Deserialize(Stream stream, SerializerFlags flags, CompressionImplementation compression, Type instanceType)
        {
            TypeSerializationInfo typeInfo = null;
            TypeSerializationArgs args     = new TypeSerializationArgs();
            object instance = Activator.CreateInstance(instanceType);

            args.Flags  = flags;
            args.Reader = GetReader(stream, flags, compression);

            typeInfo = TypeSerializationInfo.GetTypeInfo(instanceType);
            typeInfo.Deserialize(ref instance, args);

            return(instance);
        }
Example #2
0
        /// <summary>
        /// Internal use only
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="instance"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static bool Deserialize <T>(ref object instance, TypeSerializationArgs args)
        {
            TypeSerializationInfo typeInfo = null;

            //  Check arguments
            if (args.Reader == null)
            {
                Debug.Fail("Input stream is null");
                throw new ArgumentNullException("reader");
            }

            if (args.IsBaseClass)
            {
                //  For base class handling, make sure we explicitly get the type
                //  info for the template parameter
                typeInfo = TypeSerializationInfo.GetTypeInfo(typeof(T));
            }
            else
            {
                //  Otherwise use the default type detection
                typeInfo = TypeSerializationInfo.GetTypeInfo <T>(instance);
            }
            return(typeInfo.Deserialize(ref instance, args));
        }