Пример #1
0
        public override object Read(CompactBinaryReader reader)
        {
            ISerializationSurrogate decimalSurrogate = TypeSurrogateSelector.GetSurrogateForType(typeof(decimal), null);

            AverageResult result = new AverageResult();

            result.Sum   = (decimal)decimalSurrogate.Read(reader);
            result.Count = (decimal)decimalSurrogate.Read(reader);
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Reads an object of type <see cref="object"/> from the current stream
        /// and advances the stream position.
        /// </summary>
        /// <returns>object read from the stream</returns>
        public override object ReadObject()
        {
            // read type handle
            short handle = reader.ReadInt16();
            // Find an appropriate surrogate by handle
            ISerializationSurrogate surrogate =
                TypeSurrogateSelector.GetSurrogateForTypeHandle(handle, context.CacheContext);

            object obj = null;

            try
            {
                obj = surrogate.Read(this);
            }
            catch (CompactSerializationException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CompactSerializationException(e.Message, e);
            }

            return(obj);
        }
Пример #3
0
        /// <summary>
        /// Deserializes an object from the specified compact binary writer.
        /// </summary>
        /// <param name="reader">Stream containing reader</param>
        /// <param name="cacheContext">Name of the cache</param>
        /// <param name="skip">True to skip the bytes returning null</param>
        static internal object Deserialize(CompactBinaryReader reader, string cacheContext, bool skip)
        {
            // read type handle
            short handle = reader.ReadInt16();

            reader.Context.CacheContext = cacheContext;
            // Find an appropriate surrogate by handle
            ISerializationSurrogate surrogate =
                TypeSurrogateSelector.GetSurrogateForTypeHandle(handle, cacheContext);

            if (surrogate == null)
            {
                surrogate = TypeSurrogateSelector.GetSurrogateForSubTypeHandle(handle, reader.ReadInt16(), cacheContext);
            }

            if (surrogate == null)
            {
                throw new CompactSerializationException("Type handle " + handle + "is not registered with Compact Serialization Framework");
            }
            if (!skip)
            {
                return(surrogate.Read(reader));
            }
            else
            {
                surrogate.Skip(reader);
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// Reads an object of type <see cref="object"/> from the current stream
        /// and advances the stream position.
        /// </summary>
        /// <returns>object read from the stream</returns>
        public override object ReadObject()
        {
            // read type handle
            short handle = reader.ReadInt16();
            // Find an appropriate surrogate by handle
            ISerializationSurrogate surrogate =
                TypeSurrogateSelector.GetSurrogateForTypeHandle(handle, context.CacheContext);


            if (surrogate == null)
            {
                surrogate = TypeSurrogateSelector.GetSurrogateForSubTypeHandle(handle, reader.ReadInt16(), context.CacheContext);
            }

            //If surrogate not found defaultSurrogate is returned
            //if (surrogate == null) throw new CompactSerializationException("Type handle " + handle + " is not registered with Compact Serialization Framework");

            object obj = null;

            try
            {
                obj = surrogate.Read(this);
            }
            catch (CompactSerializationException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CompactSerializationException(e.Message, e);
            }

            return(obj);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override object ReadObject()
        {
            short handle = _reader.ReadInt16();
            ISerializationSurrogate surrogateForTypeHandle = TypeSurrogateSelector.GetSurrogateForTypeHandle(handle, _context.CacheContext);

            if (surrogateForTypeHandle == null)
            {
                surrogateForTypeHandle = TypeSurrogateSelector.GetSurrogateForSubTypeHandle(handle, _reader.ReadInt16(), _context.CacheContext);
            }
            object obj2 = null;

            try
            {
                obj2 = surrogateForTypeHandle.Read(this);
            }
            catch (CompactSerializationException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new CompactSerializationException(exception.Message);
            }
            return(obj2);
        }
Пример #6
0
        public override object Read(CompactBinaryReader reader)
        {
            // read type handle
            short handle = reader.ReadInt16();

            // Find an appropriate surrogate by handle
            ISerializationSurrogate typeSurr = TypeSurrogateSelector.GetSurrogateForTypeHandle(handle, null);

            if (typeSurr == null)
            {
                typeSurr = TypeSurrogateSelector.GetSurrogateForSubTypeHandle(handle, reader.ReadInt16(), reader.Context.CacheContext);
            }

            int length = reader.ReadInt32();

            T?[] array = new T?[length];
            while (true)
            {
                int index = reader.ReadInt32();
                if (index < 0)
                {
                    break;
                }

                array[index] = (T)typeSurr.Read(reader);
            }
            return(array);
        }
Пример #7
0
        public override T ReadObjectAs <T>()
        {
            // Find an appropriate surrogate by type
            ISerializationSurrogate surrogate =
                TypeSurrogateSelector.GetSurrogateForType(typeof(T), context.CacheContext);

            return((T)surrogate.Read(this));
        }
Пример #8
0
        public override object Read(CompactBinaryReader reader)
        {
            // Find an appropriate surrogate by handle
            short handle = reader.ReadInt16();
            ISerializationSurrogate typeSurr = TypeSurrogateSelector.GetSurrogateForTypeHandle(handle, reader.Context.CacheContext);

            return(Enum.ToObject(ActualType, typeSurr.Read(reader)));
        }
        /// <summary>
        /// Deserializes an object from the specified compact binary writer.
        /// </summary>
        /// <param name="writer">specified compact binary writer</param>
        /// <param name="graph">object</param>
        static internal object Deserialize(CompactBinaryReader reader)
        {
            // read type handle
            short handle = reader.ReadInt16();
            // Find an appropriate surrogate by handle
            ISerializationSurrogate surrogate =
                TypeSurrogateProvider.GetSurrogateForTypeHandle(handle);

            return(surrogate.Read(reader));
        }