コード例 #1
0
        /// <summary>
        ///		Deserialize collection items with specified <see cref="Unpacker"/> and stores them to <paramref name="collection"/>.
        /// </summary>
        /// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree.</param>
        /// <param name="collection">Collection that the items to be stored.</param>
        /// <exception cref="ArgumentNullException">
        ///		<paramref name="unpacker"/> is <c>null</c>.
        ///		Or <paramref name="collection"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="SerializationException">
        ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
        /// </exception>
        /// <exception cref="MessageTypeException">
        ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
        /// </exception>
        /// <exception cref="InvalidMessagePackStreamException">
        ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
        /// </exception>
        /// <exception cref="NotSupportedException">
        ///		<typeparamref name="T"/> is not collection.
        /// </exception>
        public void UnpackTo(Unpacker unpacker, T collection)
        {
            // TODO: Hot-Path-Optimization
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (collection == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (!unpacker.Data.HasValue)
            {
                throw SerializationExceptions.NewEmptyOrUnstartedUnpacker();
            }

            if (unpacker.Data.Value.IsNil)
            {
                return;
            }

            this.UnpackToCore(unpacker, collection);
        }
コード例 #2
0
        void IMessagePackSerializer.UnpackTo(Unpacker unpacker, object collection)
        {
            // TODO: Hot-Path-Optimization
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            if (!(collection is T))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "'{0}' is not compatible for '{1}'.", collection.GetType(), typeof(T)), "collection");
            }

            if (!unpacker.Data.HasValue)
            {
                throw SerializationExceptions.NewEmptyOrUnstartedUnpacker();
            }

            this.UnpackToCore(unpacker, ( T )collection);
        }
コード例 #3
0
        /// <summary>
        ///		Deserialize object with specified <see cref="Unpacker"/>.
        /// </summary>
        /// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree.</param>
        /// <returns>Deserialized object.</returns>
        /// <exception cref="ArgumentNullException">
        ///		<paramref name="unpacker"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="SerializationException">
        ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
        /// </exception>
        /// <exception cref="MessageTypeException">
        ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
        /// </exception>
        /// <exception cref="InvalidMessagePackStreamException">
        ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
        /// </exception>
        /// <exception cref="NotSupportedException">
        ///		<typeparamref name="T"/> is abstract type.
        /// </exception>
        public T UnpackFrom(Unpacker unpacker)
        {
            // TODO: Hot-Path-Optimization
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (!unpacker.Data.HasValue)
            {
                throw SerializationExceptions.NewEmptyOrUnstartedUnpacker();
            }

            if (unpacker.Data.GetValueOrDefault().IsNil)
            {
                if (_isNullable)
                {
                    // null
                    return(default(T));
                }
                else
                {
                    throw SerializationExceptions.NewValueTypeCannotBeNull(typeof(T));
                }
            }

            return(this.UnpackFromCore(unpacker));
        }
コード例 #4
0
 public T UnpackFrom(Unpacker unpacker)
 {
     if (unpacker == null)
     {
         throw new ArgumentNullException("unpacker");
     }
     if (!unpacker.Data.HasValue)
     {
         throw SerializationExceptions.NewEmptyOrUnstartedUnpacker();
     }
     if (unpacker.Data.GetValueOrDefault().IsNil)
     {
         if (!MessagePackSerializer <T> ._isNullable)
         {
             throw SerializationExceptions.NewValueTypeCannotBeNull(typeof(T));
         }
         return(default(T));
     }
     return(this.UnpackFromCore(unpacker));
 }