コード例 #1
0
        /// <summary>
        /// Deserializes the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="serializationContext">The serialization context.</param>
        public virtual void Deserialize(ModelBase model, TSerializationContext serializationContext)
        {
            Argument.IsNotNull("model", model);
            Argument.IsNotNull("context", serializationContext);

            using (var finalContext = GetContext(model, serializationContext, SerializationContextMode.Deserialization))
            {
                bool?previousLeanAndMeanValue = null;
                if (!ModelBase.GlobalLeanAndMeanModel)
                {
                    previousLeanAndMeanValue = model.LeanAndMeanModel;
                    model.LeanAndMeanModel   = true;
                }

                var serializerModifiers = SerializationManager.GetSerializerModifiers(finalContext.ModelType);

                Log.Debug("Using '{0}' serializer modifiers to deserialize type '{1}'", serializerModifiers.Length, finalContext.ModelType.GetSafeFullName());

                var serializingEventArgs = new SerializationEventArgs(finalContext);

                Deserializing.SafeInvoke(this, serializingEventArgs);

                foreach (var serializerModifier in serializerModifiers)
                {
                    serializerModifier.OnDeserializing(finalContext, model);
                }

                BeforeDeserialization(finalContext);

                DeserializeMembers(finalContext);

                AfterDeserialization(finalContext);

                foreach (var serializerModifier in serializerModifiers)
                {
                    serializerModifier.OnDeserialized(finalContext, model);
                }

                Deserialized.SafeInvoke(this, serializingEventArgs);

                model.FinishDeserialization();

                if (previousLeanAndMeanValue.HasValue)
                {
                    model.LeanAndMeanModel = previousLeanAndMeanValue.Value;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Deserializes the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="context">The serialization context.</param>
        protected virtual object Deserialize(object model, ISerializationContext <TSerializationContext> context)
        {
            Argument.IsNotNull("model", model);
            Argument.IsNotNull("context", context);

            var serializerModifiers = SerializationManager.GetSerializerModifiers(context.ModelType);

            Log.Debug("Using '{0}' serializer modifiers to deserialize type '{1}'", serializerModifiers.Length, context.ModelTypeName);

            var serializingEventArgs = new SerializationEventArgs(context);

            Deserializing.SafeInvoke(this, serializingEventArgs);

            foreach (var serializerModifier in serializerModifiers)
            {
                serializerModifier.OnDeserializing(context, model);
            }

            BeforeDeserialization(context);

            DeserializeMembers(context);

            // Always use the deserialized model (might be a value type)
            model = context.Model;

            AfterDeserialization(context);

            foreach (var serializerModifier in serializerModifiers)
            {
                serializerModifier.OnDeserialized(context, model);
            }

            Deserialized.SafeInvoke(this, serializingEventArgs);

            return(model);
        }