public override void ValidateAfterChildrenAdded()
        {
            base.ValidateAfterChildrenAdded();

            var defaultSerializer = OROptimizer.Serializer.TypeBasedSimpleSerializerAggregator.GetDefaultSerializerAggregator();

            var serializerAggregatorObject = _createInstanceFromTypeAndConstructorParameters.CreateInstance(this,
                                                                                                            typeof(ITypeBasedSimpleSerializerAggregator), _serializerAggregatorType, _parameters?.AllParameters ?? Array.Empty <IParameterElement>());

            TypeBasedSimpleSerializerAggregator = (ITypeBasedSimpleSerializerAggregator)serializerAggregatorObject;

            if (_parameterSerializersCollection != null)
            {
                foreach (var parameterSerializer in _parameterSerializersCollection.AllSerializers)
                {
                    if (parameterSerializer.Serializer == null)
                    {
                        LogHelper.Context.Log.WarnFormat("The value of '{0}.{1}' should not be null.", typeof(IParameterSerializer).FullName, nameof(IParameterSerializer.Serializer));
                        continue;
                    }

                    var defaultSerializerForType = defaultSerializer.GetSerializerForType(parameterSerializer.Serializer.SerializedType);
                    if (defaultSerializerForType != null)
                    {
                        LogHelper.Context.Log.InfoFormat("Replacing default serializer for type '{0}' with a serializer '{1}'. The default serializer was '{2}'.",
                                                         parameterSerializer.Serializer.SerializedType.GetTypeNameInCSharpClass(),
                                                         parameterSerializer.Serializer.GetType().GetTypeNameInCSharpClass(),
                                                         defaultSerializerForType.GetType().GetTypeNameInCSharpClass());

                        TypeBasedSimpleSerializerAggregator.UnRegister(parameterSerializer.Serializer.SerializedType);
                    }

                    TypeBasedSimpleSerializerAggregator.Register(parameterSerializer.Serializer);
                }
            }

            foreach (var serializer in defaultSerializer.GetRegisteredSerializers())
            {
                if (!TypeBasedSimpleSerializerAggregator.HasSerializerForType(serializer.SerializedType))
                {
                    TypeBasedSimpleSerializerAggregator.Register(serializer);
                }
            }

            LogSerializersData();
        }
Ejemplo n.º 2
0
 static TypeBasedSimpleSerializerAggregator()
 {
     _defaultSerializerAggregator = new TypeBasedSimpleSerializerAggregator();
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerDouble());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerLong());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerInt());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerShort());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerByte());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerBoolean());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerDateTime());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerGuid());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerString());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerType());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerAssembly());
 }