ThrowIsNotArrayHeader() public static méthode

This is intended to MsgPack for CLI internal use. Do not use this type from application directly. Throws an exception to notify that unpacker is not in the array header, that is the state is invalid.
Always thrown.
public static ThrowIsNotArrayHeader ( Unpacker unpacker ) : void
unpacker Unpacker The unpacker for pretty message.
Résultat void
Exemple #1
0
        public static void UnpackArrayTo <T>(Unpacker unpacker, MessagePackSerializer <T> serializer, T[] array)
        {
            if (unpacker == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

            if (serializer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("serializer");
            }

            if (array == null)
            {
                SerializationExceptions.ThrowArgumentNullException("array");
            }

#if ASSERT
            Contract.Assert(unpacker != null);
            Contract.Assert(serializer != null);
            Contract.Assert(array != null);
#endif // ASSERT

            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowIsNotArrayHeader(unpacker);
            }

#if ASSERT
            Contract.EndContractBlock();
#endif // ASSERT

            int count = GetItemsCount(unpacker);
            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    SerializationExceptions.ThrowMissingItem(i, unpacker);
                }

                T item;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    item = serializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        item = serializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                array[i] = item;
            }
        }
Exemple #2
0
        public static void UnpackCollectionTo <TDiscarded>(Unpacker unpacker, IEnumerable collection, Func <object, TDiscarded> addition)
        {
            if (unpacker == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

            if (collection == null)
            {
                SerializationExceptions.ThrowArgumentNullException("collection");
            }

            if (addition == null)
            {
                SerializationExceptions.ThrowArgumentNullException("addition");
            }

#if ASSERT
            Contract.Assert(unpacker != null);
            Contract.Assert(collection != null);
            Contract.Assert(addition != null);
#endif // ASSERT

            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowIsNotArrayHeader(unpacker);
            }

#if ASSERT
            Contract.EndContractBlock();
#endif // ASSERT

            int count = GetItemsCount(unpacker);
            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    SerializationExceptions.ThrowMissingItem(i, unpacker);
                }

                MessagePackObject item;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    item = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        item = _messagePackObjectSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                addition(item);
            }
        }