/// <summary> /// Serializes the members. /// </summary> /// <param name="context">The context.</param> /// <param name="membersToSerialize">The members to serialize.</param> protected virtual void SerializeMembers(ISerializationContext <TSerializationContextInfo> 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?.Invoke(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?.Invoke(this, memberSerializationEventArgs); } } }
/// <summary> /// Ends member serialization by invoking all the right events and running the modifiers. /// </summary> /// <param name="context">The serialization context.</param> /// <param name="member">The member that has been deserialized.</param> protected void EndMemberSerialization(ISerializationContext <TSerializationContextInfo> context, MemberValue member) { SerializeMember(context, member); AfterSerializeMember(context, member); SerializedMember?.Invoke(this, new MemberSerializationEventArgs(context, member)); }