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
Beispiel #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);
            }
        }
        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);
        }
Beispiel #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);
        }
        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);
        }
        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);
            }
        }