Esempio n. 1
0
        public fsSerializer()
        {
            _cachedConverterTypeInstances = new Dictionary <Type, fsBaseConverter>();
            _cachedConverters             = new Dictionary <Type, fsBaseConverter>();
            _cachedProcessors             = new Dictionary <Type, List <fsObjectProcessor> >();

            _references          = new fsCyclicReferenceManager();
            _lazyReferenceWriter = new fsLazyCycleDefinitionWriter();

            // note: The order here is important. Items at the beginning of this
            //       list will be used before converters at the end. Converters
            //       added via AddConverter() are added to the front of the list.
            _availableConverters = new List <fsConverter> {
                new fsNullableConverter {
                    Serializer = this
                },
                new fsGuidConverter {
                    Serializer = this
                },
                new fsTypeConverter {
                    Serializer = this
                },
                new fsDateConverter {
                    Serializer = this
                },
                new fsEnumConverter {
                    Serializer = this
                },
                new fsPrimitiveConverter {
                    Serializer = this
                },
                new fsArrayConverter {
                    Serializer = this
                },
                new fsDictionaryConverter {
                    Serializer = this
                },
                new fsIEnumerableConverter {
                    Serializer = this
                },
                new fsKeyValuePairConverter {
                    Serializer = this
                },
                new fsWeakReferenceConverter {
                    Serializer = this
                },
                new fsReflectedConverter {
                    Serializer = this
                }
            };
            _availableDirectConverters = new Dictionary <Type, fsDirectConverter>();

            _processors = new List <fsObjectProcessor>()
            {
                new fsSerializationCallbackProcessor()
            };

#if !NO_UNITY
            _processors.Add(new fsSerializationCallbackReceiverProcessor());
#endif

            _abstractTypeRemap = new Dictionary <Type, Type>();
            SetDefaultStorageType(typeof(ICollection <>), typeof(List <>));
            SetDefaultStorageType(typeof(IList <>), typeof(List <>));
            SetDefaultStorageType(typeof(IDictionary <,>), typeof(Dictionary <,>));

            Context = new fsContext();
            Config  = new fsConfig();

            // Register the converters from the registrar
            foreach (var converterType in fsConverterRegistrar.Converters)
            {
                AddConverter((fsBaseConverter)Activator.CreateInstance(converterType));
            }
        }