Exemple #1
0
        /// <summary>
        /// Serializes the members.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="membersToSerialize">The members to serialize.</param>
        protected virtual void SerializeMembers(ISerializationContext <TSerializationContext> context, List <MemberValue> membersToSerialize)
        {
            ApiCop.UpdateRule <InitializationApiCopRule>("SerializerBase.WarmupAtStartup",
                                                         x => x.SetInitializationMode(InitializationMode.Lazy, GetType().GetSafeFullName(false)));

            if (membersToSerialize.Count == 0)
            {
                return;
            }

            using (GetCurrentSerializationScopeManager(context.Configuration))
            {
                var serializerModifiers = SerializationManager.GetSerializerModifiers(context.ModelType);

                foreach (var member in membersToSerialize)
                {
                    bool skipByModifiers = false;
                    foreach (var serializerModifier in serializerModifiers)
                    {
                        if (serializerModifier.ShouldIgnoreMember(context, context.Model, member))
                        {
                            skipByModifiers = true;
                            break;
                        }
                    }

                    if (skipByModifiers)
                    {
                        continue;
                    }

                    var memberSerializationEventArgs = new MemberSerializationEventArgs(context, member);

                    SerializingMember.SafeInvoke(this, memberSerializationEventArgs);

                    BeforeSerializeMember(context, member);

                    foreach (var serializerModifier in serializerModifiers)
                    {
                        serializerModifier.SerializeMember(context, member);
                    }

                    if (ShouldSerializeUsingParseAndToString(member, true))
                    {
                        var objectToStringValue = SerializeUsingObjectToString(context, member);
                        if (!string.IsNullOrWhiteSpace(objectToStringValue))
                        {
                            member.Value = objectToStringValue;
                        }
                    }

                    SerializeMember(context, member);

                    AfterSerializeMember(context, member);

                    SerializedMember.SafeInvoke(this, memberSerializationEventArgs);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Serializes the members.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="membersToSerialize">The members to serialize.</param>
        protected virtual void SerializeMembers(ISerializationContext <TSerializationContext> context, List <MemberValue> membersToSerialize)
        {
            ApiCop.UpdateRule <InitializationApiCopRule>("SerializerBase.WarmupAtStartup",
                                                         x => x.SetInitializationMode(InitializationMode.Lazy, GetType().GetSafeFullName()));

            var scopeName = SerializationContextHelper.GetSerializationReferenceManagerScopeName();

            using (ScopeManager <ISerializer> .GetScopeManager(scopeName, () => this))
            {
                var serializerModifiers = SerializationManager.GetSerializerModifiers(context.ModelType);

                foreach (var member in membersToSerialize)
                {
                    bool skipByModifiers = false;
                    foreach (var serializerModifier in serializerModifiers)
                    {
                        if (serializerModifier.ShouldIgnoreMember(context, context.Model, member))
                        {
                            skipByModifiers = true;
                            break;
                        }
                    }

                    if (skipByModifiers)
                    {
                        continue;
                    }

                    var memberSerializationEventArgs = new MemberSerializationEventArgs(context, member);

                    SerializingMember.SafeInvoke(this, memberSerializationEventArgs);

                    BeforeSerializeMember(context, member);

                    foreach (var serializerModifier in serializerModifiers)
                    {
                        serializerModifier.SerializeMember(context, member);
                    }

                    SerializeMember(context, member);

                    AfterSerializeMember(context, member);

                    SerializedMember.SafeInvoke(this, memberSerializationEventArgs);
                }
            }
        }
        /// <summary>
        /// Serializes the members.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="membersToSerialize">The members to serialize.</param>
        protected virtual void SerializeMembers(ISerializationContext <TSerializationContext> context, List <MemberValue> membersToSerialize)
        {
            var serializerModifiers = SerializationManager.GetSerializerModifiers(context.ModelType);

            foreach (var member in membersToSerialize)
            {
                bool skipByModifiers = false;
                foreach (var serializerModifier in serializerModifiers)
                {
                    if (serializerModifier.ShouldIgnoreMember(context, context.Model, member))
                    {
                        skipByModifiers = true;
                        break;
                    }
                }

                if (skipByModifiers)
                {
                    continue;
                }

                var memberSerializationEventArgs = new MemberSerializationEventArgs(context, member);

                SerializingMember.SafeInvoke(this, memberSerializationEventArgs);

                BeforeSerializeMember(context, member);

                foreach (var serializerModifier in serializerModifiers)
                {
                    serializerModifier.SerializeMember(context, member);
                }

                SerializeMember(context, member);

                AfterSerializeMember(context, member);

                SerializedMember.SafeInvoke(this, memberSerializationEventArgs);
            }
        }