ShouldSerialize() public method

Determines whether a value should be serialized
public ShouldSerialize ( object obj, object value ) : bool
obj object The object.
value object The value.
return bool
コード例 #1
0
        private void SerializeMember(BsonWriter bsonWriter, object obj, BsonMemberMap memberMap)
        {
            var value = memberMap.Getter(obj);

            if (!memberMap.ShouldSerialize(obj, value))
            {
                return; // don't serialize member
            }

            bsonWriter.WriteName(memberMap.ElementName);
            var nominalType = memberMap.MemberType;

            if (value == null && nominalType.IsInterface)
            {
                bsonWriter.WriteNull();
            }
            else if (value == null && memberMap.MemberTypeIsBsonValue)
            {
                bsonWriter.WriteStartDocument();
                bsonWriter.WriteBoolean("_csharpnull", true);
                bsonWriter.WriteEndDocument();
            }
            else
            {
                var actualType = (value == null) ? nominalType : value.GetType();
                var serializer = memberMap.GetSerializer(actualType);
                serializer.Serialize(bsonWriter, nominalType, value, memberMap.SerializationOptions);
            }
        }
コード例 #2
0
        private void SerializeNormalMember(BsonSerializationContext context, object obj, BsonMemberMap memberMap)
        {
            var bsonWriter = context.Writer;

            var value = memberMap.Getter(obj);

            if (!memberMap.ShouldSerialize(obj, value))
            {
                return; // don't serialize member
            }

            bsonWriter.WriteName(memberMap.ElementName);
            memberMap.GetSerializer().Serialize(context, value);
        }
コード例 #3
0
        private void SerializeMember(BsonWriter bsonWriter, object obj, BsonMemberMap memberMap)
        {
            var value = memberMap.Getter(obj);

            if (!memberMap.ShouldSerialize(obj, value))
            {
                return; // don't serialize member
            }

            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);
        }
コード例 #4
0
        private void SerializeMember(BsonWriter bsonWriter, object obj, BsonMemberMap memberMap)
        {
            var value = memberMap.Getter(obj);

            if (!memberMap.ShouldSerialize(obj, value))
            {
                return; // don't serialize member
            }

            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);
        }
コード例 #5
0
        private void SerializeMember(BsonWriter bsonWriter, object obj, BsonMemberMap memberMap)
        {
            var value = memberMap.Getter(obj);

            if (!memberMap.ShouldSerialize(obj, value))
            {
                return; // don't serialize member
            }

            bsonWriter.WriteName(memberMap.ElementName);
            var nominalType = memberMap.MemberType;
            if (value == null && nominalType.IsInterface)
            {
                bsonWriter.WriteNull();
            }
            else if (value == null && memberMap.MemberTypeIsBsonValue)
            {
                bsonWriter.WriteStartDocument();
                bsonWriter.WriteBoolean("_csharpnull", true);
                bsonWriter.WriteEndDocument();
            }
            else
            {
                var actualType = (value == null) ? nominalType : value.GetType();
                var serializer = memberMap.GetSerializer(actualType);
                serializer.Serialize(bsonWriter, nominalType, value, memberMap.SerializationOptions);
            }
        }