SetSerializer() public method

Sets the serializer.
public SetSerializer ( IBsonSerializer serializer ) : BsonMemberMap
serializer IBsonSerializer The serializer.
return BsonMemberMap
        /// <summary>
        /// Applies the specified member map convention.
        /// </summary>
        /// <param name="memberMap">The member map convention.</param>
        public void Apply(BsonMemberMap memberMap)
        {
            Func<Type, IBsonSerializer> converter = t =>
                {
                    if (t == typeof(DateTime))
                        return new DateTimeSerializer(DateTimeKind.Local);
                    else if (t == typeof(DateTime?))
                        return new NullableSerializer<DateTime>(new DateTimeSerializer(DateTimeKind.Local));
                    return null;
                };

            IBsonSerializer serializer = null;
            switch (memberMap.MemberInfo.MemberType)
            {
                case MemberTypes.Property:
                    PropertyInfo propertyInfo = (PropertyInfo)memberMap.MemberInfo;
                    serializer = converter(propertyInfo.PropertyType);
                    break;
                case MemberTypes.Field:
                    FieldInfo fieldInfo = (FieldInfo)memberMap.MemberInfo;
                    serializer = converter(fieldInfo.FieldType);
                    break;
                default:
                    break;
            }

            if (serializer != null)
                memberMap.SetSerializer(serializer);
        }
 /// <summary>
 /// Changes the decimal representation if the member is a decimal
 /// </summary>
 /// <param name="memberMap"></param>
 public void Apply(BsonMemberMap memberMap)
 {
     if (memberMap.MemberType == typeof(string) && memberMap.ClassMap.IdMemberMap == memberMap)
     {
         memberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
     }
 }
 public void Apply(BsonMemberMap memberMap)
 {
     if (memberMap.MemberType.IsEnum)
     {
         var serializer = memberMap.GetSerializer();
         var camelCaseValueSerializer = new CamelCaseValueSerializer(serializer);
         memberMap.SetSerializer(camelCaseValueSerializer);
     }
 }
示例#4
0
 public void Apply(BsonMemberMap memberMap)
 {
     if (!memberMap.MemberType.IsEnum) return;
     memberMap.SetSerializer(new StringEnumBsonSerializer(memberMap.MemberType));
 }
示例#5
0
 public void Apply(BsonMemberMap memberMap)
 {
     memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer()));
 }