public DefaultSerializerStrategyFactory([NotNull] IEnumerable <DecoratorHandler> handlers, [NotNull] IContextualSerializerProvider serializerProvider, [NotNull] ISerializerStrategyFactory fallbackFactory, [NotNull] IContextualSerializerLookupKeyFactory lookupKeyFactory, ISerializerStrategyRegistry strategyRegistry) { if (serializerProvider == null) { throw new ArgumentNullException(nameof(serializerProvider), $"Provided {nameof(IContextualSerializerProvider)} service was null."); } if (handlers == null) { throw new ArgumentNullException(nameof(handlers), $"Provided {nameof(DecoratorHandler)}s were null. Must be a non-null collection."); } if (fallbackFactory == null) { throw new ArgumentNullException(nameof(fallbackFactory), $"Provided {nameof(ISerializerStrategyFactory)} service was null."); } if (lookupKeyFactory == null) { throw new ArgumentNullException(nameof(lookupKeyFactory), $"Provided {nameof(IContextualSerializerLookupKeyFactory)} service was null."); } lookupKeyFactoryService = lookupKeyFactory; StrategyRegistry = strategyRegistry ?? throw new ArgumentNullException(nameof(strategyRegistry)); decoratorHandlers = handlers; serializerProviderService = serializerProvider; fallbackFactoryService = fallbackFactory; }
public static IEnumerable <DecoratorHandler> Create([NotNull] IContextualSerializerProvider serializerProvider, [NotNull] IContextualSerializerLookupKeyFactory lookupKeyFactory, [NotNull] ISerializerStrategyFactory fallbackFactory) { if (serializerProvider == null) { throw new ArgumentNullException(nameof(serializerProvider)); } if (lookupKeyFactory == null) { throw new ArgumentNullException(nameof(lookupKeyFactory)); } if (lookupKeyFactory == null) { throw new ArgumentNullException(nameof(lookupKeyFactory)); } //Order matters. The last handler act as the essentially a default handler except it does still have some requirements but not much return(new List <DecoratorHandler> { new SpecialComplexTypeSerializerDecoratorhandler(serializerProvider), //handles special inaccessible types like DateTime new PrimitiveTypeSerializerDecoratorHandler(serializerProvider), new ArraySerializerDecoratorHandler(serializerProvider), new EnumSerializerDecoratorHandler(serializerProvider, fallbackFactory), new StringSerializerDecoratorHandler(serializerProvider), new SubComplexTypeSerializerDecoratorHandler(serializerProvider, new MemberSerializationMediatorFactory(serializerProvider, lookupKeyFactory)), new ComplexTypeSerializerDecoratorHandler(serializerProvider, new MemberSerializationMediatorFactory(serializerProvider, lookupKeyFactory)) //it's important that this is the final/last handler }); }
public EnumSerializerDecoratorHandler(IContextualSerializerProvider serializerProvider, ISerializerStrategyFactory fallbackFactory) : base(serializerProvider) { if (fallbackFactory == null) { throw new ArgumentNullException(nameof(fallbackFactory), $"Provided argument {nameof(fallbackFactory)} was null."); } fallbackFactoryService = fallbackFactory; }