Пример #1
0
        private void SerializeMember(
            BsonWriter bsonWriter,
            object obj,
            BsonMemberMap memberMap
            )
        {
            var value = memberMap.Getter(obj);

            if (value == null && memberMap.IgnoreIfNull)
            {
                return; // don't serialize null value
            }
            if (memberMap.HasDefaultValue && !memberMap.SerializeDefaultValue && object.Equals(value, memberMap.DefaultValue))
            {
                return; // don't serialize default value
            }
            if (!memberMap.ShouldSerializeMethod(obj))
            {
                return; // the ShouldSerializeMethod determined that the member shouldn't be serialized
            }

            bsonWriter.WriteName(memberMap.ElementName);
            var nominalType = memberMap.MemberType;
            var actualType  = (value == null) ? nominalType : value.GetType();
            var serializer  = memberMap.GetSerializer(actualType);

            serializer.Serialize(bsonWriter, nominalType, value, memberMap.SerializationOptions);
        }
        private void SerializeMember(
            BsonWriter bsonWriter,
            object obj,
            BsonMemberMap memberMap
        ) {
            var value = memberMap.Getter(obj);
            if (value == null && memberMap.IgnoreIfNull) {
                return; // don't serialize null value
            }
            if (memberMap.HasDefaultValue && !memberMap.SerializeDefaultValue && object.Equals(value, memberMap.DefaultValue)) {
                return; // don't serialize default value
            }
            if (!memberMap.ShouldSerializeMethod(obj)) {
                return; // the ShouldSerializeMethod determined that the member shouldn't be serialized
            }

            bsonWriter.WriteName(memberMap.ElementName);
            var nominalType = memberMap.MemberType;
            var actualType = (value == null) ? nominalType : value.GetType();
            var serializer = memberMap.GetSerializer(actualType);
            serializer.Serialize(bsonWriter, nominalType, value, memberMap.SerializationOptions);
        }
		private void SerializeMember(BsonWriter bsonWriter, object obj, BsonMemberMap memberMap)
		{
			object objA = memberMap.Getter(obj);
			if (objA == null && memberMap.IgnoreIfNull || (memberMap.HasDefaultValue && !memberMap.SerializeDefaultValue && object.Equals(objA, memberMap.DefaultValue) || !memberMap.ShouldSerializeMethod(obj)))
				return;
			bsonWriter.WriteName(memberMap.ElementName);
			Type memberType = memberMap.MemberType;
			Type actualType = objA == null ? memberType : objA.GetType();
			if (IsRelation(memberMap))
				ValidateVirtualRelation(memberMap);
			memberMap.GetSerializer(actualType).Serialize(bsonWriter, memberType, objA, memberMap.SerializationOptions);
		}