Exemplo n.º 1
0
        public ReflectionEnumerableMessagePackSerializer(
            SerializationContext ownerContext,
            Type targetType,
            CollectionTraits collectionTraits,
            PolymorphismSchema itemsSchema,
            SerializationTarget targetInfo
            )
            : base(ownerContext, itemsSchema, targetInfo.GetCapabilitiesForCollection(collectionTraits))
        {
            if (targetInfo.CanDeserialize)
            {
                this._factory = ReflectionSerializerHelper.CreateCollectionInstanceFactory <TCollection, TItem>(targetInfo.DeserializationConstructor);
                this._addItem = ReflectionSerializerHelper.GetAddItem <TCollection, TItem>(targetType, collectionTraits);
            }
            else
            {
                this._factory = _ => { throw SerializationExceptions.NewCreateInstanceIsNotSupported(targetType); };
                this._addItem = (c, x) => { throw SerializationExceptions.NewUnpackFromIsNotSupported(targetType); };
            }

            this._isPackable   = typeof(IPackable).IsAssignableFrom(targetType ?? typeof(TCollection));
            this._isUnpackable = typeof(IUnpackable).IsAssignableFrom(targetType ?? typeof(TCollection));
#if FEATURE_TAP
            this._isAsyncPackable   = typeof(IAsyncPackable).IsAssignableFrom(targetType ?? typeof(TCollection));
            this._isAsyncUnpackable = typeof(IAsyncUnpackable).IsAssignableFrom(targetType ?? typeof(TCollection));
#endif // FEATURE_TAP
        }
Exemplo n.º 2
0
        public ReflectionEnumerableMessagePackSerializer(
            SerializationContext ownerContext,
            Type abstractType,
            Type concreteType,
            CollectionTraits concreteTypeCollectionTraits,
            PolymorphismSchema itemsSchema,
            SerializationTarget targetInfo
            )
            : base(ownerContext, abstractType, concreteTypeCollectionTraits, itemsSchema, targetInfo.GetCapabilitiesForCollection(concreteTypeCollectionTraits))
        {
            if (targetInfo.CanDeserialize)
            {
                this._factory = ReflectionSerializerHelper.CreateCollectionInstanceFactory(abstractType, concreteType, concreteTypeCollectionTraits.ElementType, targetInfo.DeserializationConstructor);
                this._addItem = ReflectionSerializerHelper.GetAddItem(concreteType, concreteTypeCollectionTraits);
            }
            else
            {
                this._factory = _ => { throw SerializationExceptions.NewCreateInstanceIsNotSupported(concreteType); };
                this._addItem = (c, x) => { throw SerializationExceptions.NewUnpackFromIsNotSupported(concreteType); };
            }

            this._isPackable   = typeof(IPackable).IsAssignableFrom(concreteType ?? abstractType);
            this._isUnpackable = typeof(IUnpackable).IsAssignableFrom(concreteType ?? abstractType);
        }