Example #1
0
        public SerializerBuilder()
        {
            typeInspectorFactories.Add(typeof(CachedTypeInspector), inner => new CachedTypeInspector(inner));
            typeInspectorFactories.Add(typeof(NamingConventionTypeInspector), inner => namingConvention != null ? new NamingConventionTypeInspector(inner, namingConvention) : inner);
            typeInspectorFactories.Add(typeof(YamlAttributesTypeInspector), inner => new YamlAttributesTypeInspector(inner));
            typeInspectorFactories.Add(typeof(YamlAttributeOverridesInspector), inner => overrides != null ? new YamlAttributeOverridesInspector(inner, overrides.Clone()) : inner);

            preProcessingPhaseObjectGraphVisitorFactories = new LazyComponentRegistrationList <IEnumerable <IYamlTypeConverter>, IObjectGraphVisitor <Nothing> >();
            preProcessingPhaseObjectGraphVisitorFactories.Add(typeof(AnchorAssigner), typeConverters => new AnchorAssigner(typeConverters));

            emissionPhaseObjectGraphVisitorFactories = new LazyComponentRegistrationList <EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor <IEmitter> >();
            emissionPhaseObjectGraphVisitorFactories.Add(typeof(CustomSerializationObjectGraphVisitor),
                                                         args => new CustomSerializationObjectGraphVisitor(args.InnerVisitor, args.TypeConverters, args.NestedObjectSerializer));

            emissionPhaseObjectGraphVisitorFactories.Add(typeof(AnchorAssigningObjectGraphVisitor),
                                                         args => new AnchorAssigningObjectGraphVisitor(args.InnerVisitor, args.EventEmitter, args.GetPreProcessingPhaseObjectGraphVisitor <AnchorAssigner>()));

            emissionPhaseObjectGraphVisitorFactories.Add(typeof(DefaultExclusiveObjectGraphVisitor),
                                                         args => new DefaultExclusiveObjectGraphVisitor(args.InnerVisitor));

            eventEmitterFactories = new LazyComponentRegistrationList <IEventEmitter, IEventEmitter>();
            eventEmitterFactories.Add(typeof(TypeAssigningEventEmitter), inner => new TypeAssigningEventEmitter(inner, false, tagMappings));

            objectGraphTraversalStrategyFactory = (typeInspector, typeResolver, typeConverters) => new FullObjectGraphTraversalStrategy(typeInspector, typeResolver, maximumRecursion, namingConvention ?? new NullNamingConvention());

            WithTypeResolver(new DynamicTypeResolver());
        }
Example #2
0
 public ValueSerializer(IObjectGraphTraversalStrategy traversalStrategy, IEventEmitter eventEmitter, IEnumerable <IYamlTypeConverter> typeConverters, LazyComponentRegistrationList <IEnumerable <IYamlTypeConverter>, IObjectGraphVisitor <Nothing> > preProcessingPhaseObjectGraphVisitorFactories, LazyComponentRegistrationList <EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor <IEmitter> > emissionPhaseObjectGraphVisitorFactories)
 {
     this.traversalStrategy = traversalStrategy;
     this.eventEmitter      = eventEmitter;
     this.typeConverters    = typeConverters;
     this.preProcessingPhaseObjectGraphVisitorFactories = preProcessingPhaseObjectGraphVisitorFactories;
     this.emissionPhaseObjectGraphVisitorFactories      = emissionPhaseObjectGraphVisitorFactories;
 }
Example #3
0
 internal BuilderSkeleton()
 {
     overrides = new YamlAttributeOverrides();
     typeConverterFactories = new LazyComponentRegistrationList <Nothing, IYamlTypeConverter>();
     typeConverterFactories.Add(typeof(GuidConverter), (Nothing _) => new GuidConverter(false));
     typeConverterFactories.Add(typeof(SystemTypeConverter), (Nothing _) => new SystemTypeConverter());
     typeInspectorFactories = new LazyComponentRegistrationList <ITypeInspector, ITypeInspector>();
 }
        public static TComponent BuildComponentChain <TArgument, TComponent>(this LazyComponentRegistrationList <TArgument, TComponent> registrations, TComponent innerComponent, Func <TComponent, TArgument> argumentBuilder)
        {
            var outerComponent = registrations.InReverseOrder.Aggregate(
                innerComponent,
                (inner, factory) => factory(argumentBuilder(inner))
                );

            return(outerComponent);
        }
Example #5
0
        public LazyComponentRegistrationList <TArgument, TComponent> Clone()
        {
            var clone = new LazyComponentRegistrationList <TArgument, TComponent>();

            foreach (var entry in entries)
            {
                clone.entries.Add(entry);
            }
            return(clone);
        }
Example #6
0
        public LazyComponentRegistrationList <TArgument, TComponent> Clone()
        {
            LazyComponentRegistrationList <TArgument, TComponent> lazyComponentRegistrationList = new LazyComponentRegistrationList <TArgument, TComponent>();

            foreach (LazyComponentRegistration entry in entries)
            {
                lazyComponentRegistrationList.entries.Add(entry);
            }
            return(lazyComponentRegistrationList);
        }
        internal BuilderSkeleton(ITypeResolver typeResolver)
        {
            overrides = new YamlAttributeOverrides();

            typeConverterFactories = new LazyComponentRegistrationList <Nothing, IYamlTypeConverter>
            {
                { typeof(GuidConverter), _ => new GuidConverter(false) },
                { typeof(SystemTypeConverter), _ => new SystemTypeConverter() }
            };

            typeInspectorFactories = new LazyComponentRegistrationList <ITypeInspector, ITypeInspector>();
            this.typeResolver      = typeResolver ?? throw new ArgumentNullException(nameof(typeResolver));
        }
        /// <summary>
        /// Initializes a new <see cref="DeserializerBuilder" /> using the default component registrations.
        /// </summary>
        public DeserializerBuilder()
            : base(new StaticTypeResolver())
        {
            typeMappings  = new Dictionary <Type, Type>();
            objectFactory = new Lazy <IObjectFactory>(() => new DefaultObjectFactory(typeMappings), true);

            tagMappings = new Dictionary <TagName, Type>
            {
                { FailsafeSchema.Tags.Map, typeof(Dictionary <object, object>) },
                { FailsafeSchema.Tags.Str, typeof(string) },
                { JsonSchema.Tags.Bool, typeof(bool) },
                { JsonSchema.Tags.Float, typeof(double) },
                { JsonSchema.Tags.Int, typeof(int) },
                { DefaultSchema.Tags.Timestamp, typeof(DateTime) }
            };

            typeInspectorFactories.Add(typeof(CachedTypeInspector), inner => new CachedTypeInspector(inner));
            typeInspectorFactories.Add(typeof(NamingConventionTypeInspector), inner => namingConvention is NullNamingConvention ? inner : new NamingConventionTypeInspector(inner, namingConvention));
            typeInspectorFactories.Add(typeof(YamlAttributesTypeInspector), inner => new YamlAttributesTypeInspector(inner));
            typeInspectorFactories.Add(typeof(YamlAttributeOverridesInspector), inner => overrides != null ? new YamlAttributeOverridesInspector(inner, overrides.Clone()) : inner);
            typeInspectorFactories.Add(typeof(ReadableAndWritablePropertiesTypeInspector), inner => new ReadableAndWritablePropertiesTypeInspector(inner));

            nodeDeserializerFactories = new LazyComponentRegistrationList <Nothing, INodeDeserializer>
            {
                { typeof(YamlConvertibleNodeDeserializer), _ => new YamlConvertibleNodeDeserializer(objectFactory.Value) },
                { typeof(YamlSerializableNodeDeserializer), _ => new YamlSerializableNodeDeserializer(objectFactory.Value) },
                { typeof(TypeConverterNodeDeserializer), _ => new TypeConverterNodeDeserializer(BuildTypeConverters()) },
                { typeof(NullNodeDeserializer), _ => new NullNodeDeserializer() },
                { typeof(ScalarNodeDeserializer), _ => new ScalarNodeDeserializer() },
                { typeof(ArrayNodeDeserializer), _ => new ArrayNodeDeserializer() },
                { typeof(DictionaryNodeDeserializer), _ => new DictionaryNodeDeserializer(objectFactory.Value) },
                { typeof(CollectionNodeDeserializer), _ => new CollectionNodeDeserializer(objectFactory.Value) },
                { typeof(EnumerableNodeDeserializer), _ => new EnumerableNodeDeserializer() },
                { typeof(ObjectNodeDeserializer), _ => new ObjectNodeDeserializer(objectFactory.Value, BuildTypeInspector(), ignoreUnmatched) }
            };

            nodeTypeResolverFactories = new LazyComponentRegistrationList <Nothing, INodeTypeResolver>
            {
                { typeof(MappingNodeTypeResolver), _ => new MappingNodeTypeResolver(typeMappings) },
                { typeof(YamlConvertibleTypeResolver), _ => new YamlConvertibleTypeResolver() },
                { typeof(YamlSerializableTypeResolver), _ => new YamlSerializableTypeResolver() },
                { typeof(TagNodeTypeResolver), _ => new TagNodeTypeResolver(tagMappings) },
                { typeof(PreventUnknownTagsNodeTypeResolver), _ => new PreventUnknownTagsNodeTypeResolver() },
                { typeof(DefaultContainersNodeTypeResolver), _ => new DefaultContainersNodeTypeResolver() }
            };
        }
Example #9
0
        /// <summary>
        /// Initializes a new <see cref="DeserializerBuilder" /> using the default component registrations.
        /// </summary>
        public DeserializerBuilder()
        {
            tagMappings = new Dictionary <string, Type>
            {
                { "tag:yaml.org,2002:map", typeof(Dictionary <object, object>) },
                { "tag:yaml.org,2002:bool", typeof(bool) },
                { "tag:yaml.org,2002:float", typeof(double) },
                { "tag:yaml.org,2002:int", typeof(int) },
                { "tag:yaml.org,2002:str", typeof(string) },
                { "tag:yaml.org,2002:timestamp", typeof(DateTime) }
            };

            typeInspectorFactories.Add(typeof(CachedTypeInspector), inner => new CachedTypeInspector(inner));
            typeInspectorFactories.Add(typeof(NamingConventionTypeInspector), inner => namingConvention != null ? new NamingConventionTypeInspector(inner, namingConvention) : inner);
            typeInspectorFactories.Add(typeof(YamlAttributesTypeInspector), inner => new YamlAttributesTypeInspector(inner));
            typeInspectorFactories.Add(typeof(YamlAttributeOverridesInspector), inner => overrides != null ? new YamlAttributeOverridesInspector(inner, overrides.Clone()) : inner);
            typeInspectorFactories.Add(typeof(ReadableAndWritablePropertiesTypeInspector), inner => new ReadableAndWritablePropertiesTypeInspector(inner));

            nodeDeserializerFactories = new LazyComponentRegistrationList <Nothing, INodeDeserializer>
            {
                { typeof(YamlConvertibleNodeDeserializer), _ => new YamlConvertibleNodeDeserializer(objectFactory) },
                { typeof(YamlSerializableNodeDeserializer), _ => new YamlSerializableNodeDeserializer(objectFactory) },
                { typeof(TypeConverterNodeDeserializer), _ => new TypeConverterNodeDeserializer(BuildTypeConverters()) },
                { typeof(NullNodeDeserializer), _ => new NullNodeDeserializer() },
                { typeof(ScalarNodeDeserializer), _ => new ScalarNodeDeserializer() },
                { typeof(ArrayNodeDeserializer), _ => new ArrayNodeDeserializer() },
                { typeof(DictionaryNodeDeserializer), _ => new DictionaryNodeDeserializer(objectFactory) },
                { typeof(CollectionNodeDeserializer), _ => new CollectionNodeDeserializer(objectFactory) },
                { typeof(EnumerableNodeDeserializer), _ => new EnumerableNodeDeserializer() },
                { typeof(ObjectNodeDeserializer), _ => new ObjectNodeDeserializer(objectFactory, BuildTypeInspector(), ignoreUnmatched) }
            };

            nodeTypeResolverFactories = new LazyComponentRegistrationList <Nothing, INodeTypeResolver>
            {
                { typeof(YamlConvertibleTypeResolver), _ => new YamlConvertibleTypeResolver() },
                { typeof(YamlSerializableTypeResolver), _ => new YamlSerializableTypeResolver() },
                { typeof(TagNodeTypeResolver), _ => new TagNodeTypeResolver(tagMappings) },
                { typeof(PreventUnknownTagsNodeTypeResolver), _ => new PreventUnknownTagsNodeTypeResolver() },
                { typeof(DefaultContainersNodeTypeResolver), _ => new DefaultContainersNodeTypeResolver() }
            };

            WithTypeResolver(new StaticTypeResolver());
        }
Example #10
0
 public TrackingRegistrationLocationSelector(LazyComponentRegistrationList <TArgument, TComponent> registrations, TrackingLazyComponentRegistration newRegistration)
 {
     this.registrations   = registrations;
     this.newRegistration = newRegistration;
 }
 public static List <TComponent> BuildComponentList <TComponent>(this LazyComponentRegistrationList <Nothing, TComponent> registrations)
 {
     return(registrations
            .Select(factory => factory(default))
Example #12
0
 public static List <TComponent> BuildComponentList <TArgument, TComponent>(this LazyComponentRegistrationList <TArgument, TComponent> registrations, TArgument argument)
 {
     return(registrations
            .Select(factory => factory(argument))
            .ToList());
 }
 public static List <TComponent> BuildComponentList <TComponent>(this LazyComponentRegistrationList <Nothing, TComponent> registrations)
 {
     return(registrations
            .Select(factory => factory(Nothing.Instance))
            .ToList());
 }
 public static TComponent BuildComponentChain <TComponent>(this LazyComponentRegistrationList <TComponent, TComponent> registrations, TComponent innerComponent)
 {
     return(registrations.InReverseOrder.Aggregate(innerComponent, (TComponent inner, Func <TComponent, TComponent> factory) => factory(inner)));
 }
 public static List <TComponent> BuildComponentList <TArgument, TComponent>(this LazyComponentRegistrationList <TArgument, TComponent> registrations, TArgument argument)
 {
     return((from factory in registrations
             select factory(argument)).ToList());
 }
 public static List <TComponent> BuildComponentList <TComponent>(this LazyComponentRegistrationList <Nothing, TComponent> registrations)
 {
     return((from factory in registrations
             select factory(null)).ToList());
 }