Exemple #1
0
        public ArraySerializerDecorator([NotNull] IGeneralSerializerProvider serializerProvider, [NotNull] ICollectionSizeStrategy sizeStrategy, SerializationContextRequirement contextReq)
        {
            if (serializerProvider == null)
            {
                throw new ArgumentNullException(nameof(serializerProvider), $"Provided {nameof(IGeneralSerializerProvider)} to needed to decorate was null.");
            }

            if (sizeStrategy == null)
            {
                throw new ArgumentNullException(nameof(sizeStrategy), $"Provided {nameof(ICollectionSizeStrategy)} to needed to decorate was null.");
            }

            if (!Enum.IsDefined(typeof(SerializationContextRequirement), contextReq))
            {
                throw new ArgumentOutOfRangeException(nameof(contextReq), "Value should be defined in the SerializationContextRequirement enum.");
            }

            /*if (!Enum.IsDefined(typeof(SerializationContextRequirement), contextReq))
             *      throw new InvalidEnumArgumentException(nameof(contextReq), (int) contextReq, typeof(SerializationContextRequirement));*/

            ContextRequirement = contextReq;

            try
            {
                decoratedSerializer = serializerProvider.Get <TObjectType>();
            }
            catch (InvalidOperationException e)
            {
                throw new InvalidOperationException($"Failed to produce a serializer for Type: {typeof(TObjectType).FullName} in required {nameof(ArraySerializerDecorator<TObjectType>)}", e);
            }

            sizeStrategyService = sizeStrategy;
        }
        public ContextRequirementOverrideDecorator([NotNull] ISerializableTypeContext context,
                                                   SerializationContextRequirement requirement)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!Enum.IsDefined(typeof(SerializationContextRequirement), requirement))
            {
                throw new ArgumentOutOfRangeException(nameof(requirement), "Value should be defined in the SerializationContextRequirement enum.");
            }

            /*if (!Enum.IsDefined(typeof(SerializationContextRequirement), requirement))
             *      throw new InvalidEnumArgumentException(nameof(requirement), (int) requirement,
             *              typeof(SerializationContextRequirement));*/

            managedContext     = context;
            ContextRequirement = requirement;
        }
        public LazyLoadedSerializerStrategy(SerializationContextRequirement contextRequirement, [NotNull] Type serializerType, [NotNull] ILazySerializerProvider provider)
        {
            if (serializerType == null)
            {
                throw new ArgumentNullException(nameof(serializerType));
            }
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }
            if (!Enum.IsDefined(typeof(SerializationContextRequirement), contextRequirement))
            {
                throw new ArgumentOutOfRangeException(nameof(contextRequirement), "Value should be defined in the SerializationContextRequirement enum.");
            }

            ContextRequirement = contextRequirement;
            SerializerType     = serializerType;
            Provider           = provider;

            CastedProvidedSerializer = new Lazy <ITypeSerializerStrategy <TType> >(() => provider.SerializerStrategy.Value as ITypeSerializerStrategy <TType>, true);
        }
Exemple #4
0
        public GenericPrimitiveArraySerializerDecorator([NotNull] IGeneralSerializerProvider serializerProvider, [NotNull] ICollectionSizeStrategy sizeStrategy, SerializationContextRequirement contextReq)
        {
            if (serializerProvider == null)
            {
                throw new ArgumentNullException(nameof(serializerProvider), $"Provided {nameof(IGeneralSerializerProvider)} to needed to decorate was null.");
            }

            if (sizeStrategy == null)
            {
                throw new ArgumentNullException(nameof(sizeStrategy), $"Provided {nameof(ICollectionSizeStrategy)} to needed to decorate was null.");
            }

            if (!Enum.IsDefined(typeof(SerializationContextRequirement), contextReq))
            {
                throw new ArgumentOutOfRangeException(nameof(contextReq), "Value should be defined in the SerializationContextRequirement enum.");
            }

            ContextRequirement  = contextReq;
            SizeStrategyService = sizeStrategy;
            DecoratedSerializer = serializerProvider.Get <TType>();
        }
        public static ISerializableTypeContext Override([NotNull] this ISerializableTypeContext context, SerializationContextRequirement requirement)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (!Enum.IsDefined(typeof(SerializationContextRequirement), requirement))
            {
                throw new ArgumentOutOfRangeException(nameof(requirement), "Value should be defined in the SerializationContextRequirement enum.");
            }

            /*if (!Enum.IsDefined(typeof(SerializationContextRequirement), requirement))
             *      throw new InvalidEnumArgumentException(nameof(requirement), (int) requirement,
             *              typeof(SerializationContextRequirement));*/

            //Deocrate the context to set the provided key
            return(new ContextRequirementOverrideDecorator(context, requirement));
        }
 public StringSerializerStrategy(Encoding encodingStrategy, SerializationContextRequirement contextRequirement = SerializationContextRequirement.Contextless)
     : base(encodingStrategy)
 {
     //We may need to override this as contextual
     ContextRequirement = contextRequirement;
 }