コード例 #1
0
        /// <summary>
        /// Serializes the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="context">The context.</param>
        protected virtual void Serialize(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);

            Serializing.SafeInvoke(this, serializingEventArgs);

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

            BeforeSerialization(context);

            var members = GetSerializableMembers(context, model);

            SerializeMembers(context, members);

            AfterSerialization(context);

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

            Serialized.SafeInvoke(this, serializingEventArgs);
        }
コード例 #2
0
        /// <summary>
        /// Serializes the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="context">The context.</param>
        public virtual void Serialize(ModelBase model, TSerializationContext context)
        {
            Argument.IsNotNull("model", model);
            Argument.IsNotNull("context", context);

            using (var finalContext = GetContext(model, context, SerializationContextMode.Serialization))
            {
                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);

                Serializing.SafeInvoke(this, serializingEventArgs);

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

                BeforeSerialization(finalContext);

                var members = GetSerializableMembers(model);
                SerializeMembers(finalContext, members);

                AfterSerialization(finalContext);

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

                Serialized.SafeInvoke(this, serializingEventArgs);
            }
        }