ThrowArgumentNullException() статический приватный Метод

static private ThrowArgumentNullException ( string parameterName ) : void
parameterName string
Результат void
Пример #1
0
        public static async Task PackToMapAsync <TObject>(
            Packer packer,
            TObject target,
            IDictionary <string, Func <Packer, TObject, CancellationToken, Task> > operations,
            CancellationToken cancellationToken
            )
        {
            if (packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

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

            Contract.Assert(packer != null);
            Contract.Assert(operations != null);

            await packer.PackMapHeaderAsync(operations.Count, cancellationToken).ConfigureAwait(false);

            foreach (var operation in operations)
            {
                await packer.PackStringAsync(operation.Key, cancellationToken).ConfigureAwait(false);

                await operation.Value(packer, target, cancellationToken).ConfigureAwait(false);
            }
        }
Пример #2
0
        public static void PackToArray <TObject>(
            Packer packer,
            TObject target,
            IList <Action <Packer, TObject> > operations
            )
        {
            if (packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("packer");
            }

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

#if ASSERT
            Contract.Assert(packer != null);
            Contract.Assert(operations != null);
#endif // ASSERT

            packer.PackArrayHeader(operations.Count);
            foreach (var operation in operations)
            {
                operation(packer, target);
            }
        }
Пример #3
0
        public static async Task PackToArrayAsync <TObject>(
            Packer packer,
            TObject target,
            IList <Func <Packer, TObject, CancellationToken, Task> > operations,
            CancellationToken cancellationToken
            )
        {
            if (packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("packer");
            }

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

#if ASSERT
            Contract.Assert(packer != null);
            Contract.Assert(operations != null);
#endif // ASSERT

            await packer.PackArrayHeaderAsync(operations.Count, cancellationToken).ConfigureAwait(false);

            foreach (var operation in operations)
            {
                await operation(packer, target, cancellationToken).ConfigureAwait(false);
            }
        }
Пример #4
0
        public static void PackToMap <TObject>(
            Packer packer,
            TObject target,
            IDictionary <string, Action <Packer, TObject> > operations
            )
        {
            if (packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

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

#if ASSERT
            Contract.Assert(packer != null);
            Contract.Assert(operations != null);
#endif // ASSERT

            packer.PackMapHeader(operations.Count);
            foreach (var operation in operations)
            {
                packer.PackString(operation.Key);
                operation.Value(packer, target);
            }
        }
Пример #5
0
        public static void PackToArray <TObject>(
            ref PackToArrayParameters <TObject> parameter
            )
        {
            if (parameter.Packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("parameter", "Packer");
            }

            if (parameter.Operations == null)
            {
                SerializationExceptions.ThrowArgumentNullException("parameter", "Operations");
            }

#if ASSERT
            Contract.Assert(parameter.Packer != null);
            Contract.Assert(parameter.Operations != null);
#endif // ASSERT

            parameter.Packer.PackArrayHeader(parameter.Operations.Count);
            foreach (var operation in parameter.Operations)
            {
                operation(parameter.Packer, parameter.Target);
            }
        }
Пример #6
0
        public static void PackToArray <TObject>(
            Packer packer,
            TObject target,
            IList <Action <Packer, TObject> > operations
            )
        {
            if (packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("packer");
            }

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

            var parameter =
                new PackToArrayParameters <TObject>
            {
                Packer     = packer,
                Target     = target,
                Operations = operations
            };

            PackToArray(ref parameter);
        }
Пример #7
0
        public static Task PackToMapAsync <TObject>(
            Packer packer,
            TObject target,
            IDictionary <string, Func <Packer, TObject, CancellationToken, Task> > operations,
            CancellationToken cancellationToken
            )
        {
            if (packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("packer");
            }

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

            var parameter =
                new PackToMapAsyncParameters <TObject>
            {
                Packer            = packer,
                Target            = target,
                Operations        = operations,
                CancellationToken = cancellationToken
            };

            return(PackToMapAsync(ref parameter));
        }
Пример #8
0
        public static void PackToMap <TObject>(
            Packer packer,
            TObject target,
            IDictionary <string, Action <Packer, TObject> > operations
            )
        {
            if (packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("packer");
            }

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

            var parameter =
                new PackToMapParameters <TObject>
            {
                Packer     = packer,
                Target     = target,
                Operations = operations
            };

            PackToMap(ref parameter);
        }
Пример #9
0
        public static int GetItemsCount(Unpacker unpacker)
        {
            if (unpacker == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

            long rawItemsCount = 0L;

            try
            {
                // ReSharper disable once PossibleNullReferenceException
                rawItemsCount = unpacker.ItemsCount;
            }
            catch (InvalidOperationException ex)
            {
                SerializationExceptions.ThrowIsIncorrectStream(ex);
            }

            if (rawItemsCount > Int32.MaxValue)
            {
                SerializationExceptions.ThrowIsTooLargeCollection();
            }

            int count = unchecked (( int )rawItemsCount);

            return(count);
        }
Пример #10
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;
            }
        }
Пример #11
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);
            }
        }
Пример #12
0
        public static T InvokeUnpackFrom <T>(MessagePackSerializer <T> serializer, Unpacker unpacker)
        {
            if (serializer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("serializer");
            }

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

            return(serializer.UnpackFromCore(unpacker));
        }
Пример #13
0
        public static Task PackToMapAsync <TObject>(
            ref PackToMapAsyncParameters <TObject> parameter
            )
        {
            if (parameter.Packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("parameter", "Packer");
            }

            if (parameter.Operations == null)
            {
                SerializationExceptions.ThrowArgumentNullException("parameter", "Operations");
            }

            return(PackToMapAsyncCore(parameter.SerializationContext, parameter.Packer, parameter.Target, parameter.Operations, parameter.NullCheckers, parameter.CancellationToken));
        }
Пример #14
0
        public static void PackToMap <TObject>(
            ref PackToMapParameters <TObject> parameter
            )
        {
            if (parameter.Packer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("parameter", "Packer");
            }

            if (parameter.Operations == null)
            {
                SerializationExceptions.ThrowArgumentNullException("parameter", "Operations");
            }

#if ASSERT
            Contract.Assert(parameter.Packer != null);
            Contract.Assert(parameter.Operations != null);
#endif // ASSERT

            if (parameter.NullCheckers != null &&
                parameter.SerializationContext != null && parameter.SerializationContext.DictionarySerlaizationOptions.OmitNullEntry)
            {
#if ASSERT
                Contract.Assert(!SerializerDebugging.UseLegacyNullMapEntryHandling);
#endif // ASSERT

                // Skipping causes the entries count header reducing, so count up null entries first.
                var nullCount = 0;
                foreach (var nullChecker in parameter.NullCheckers)
                {
                    if (nullChecker.Value(parameter.Target))
                    {
                        nullCount++;
                    }
                }

                parameter.Packer.PackMapHeader(parameter.Operations.Count - nullCount);
                foreach (var operation in parameter.Operations)
                {
                    Func <TObject, bool> nullChecker;
                    if (parameter.NullCheckers.TryGetValue(operation.Key, out nullChecker))
                    {
                        if (nullChecker(parameter.Target))
                        {
                            continue;
                        }
                    }

                    parameter.Packer.PackString(operation.Key);
                    operation.Value(parameter.Packer, parameter.Target);
                }
            }
            else
            {
                parameter.Packer.PackMapHeader(parameter.Operations.Count);
                // Compatible path
                foreach (var operation in parameter.Operations)
                {
                    parameter.Packer.PackString(operation.Key);
                    operation.Value(parameter.Packer, parameter.Target);
                }
            }
#pragma warning restore 618
        }
Пример #15
0
        public static void UnpackMapTo(Unpacker unpacker, IDictionary dictionary)
        {
            if (unpacker == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

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

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

            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(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 key;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    key = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        key = _messagePackObjectSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }


                if (!unpacker.Read())
                {
                    SerializationExceptions.ThrowMissingItem(i, unpacker);
                }

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

                dictionary.Add(key, value);
            }
        }