public SetSerializationOptions ( IBsonSerializationOptions serializationOptions ) : BsonMemberMap | ||
serializationOptions | IBsonSerializationOptions | The serialization options. |
return | BsonMemberMap |
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public virtual void Apply(BsonMemberMap memberMap) { var memberSerializer = memberMap.GetSerializer(memberMap.MemberType); var memberSerializationOptions = memberMap.SerializationOptions; if (memberSerializationOptions == null) { var memberDefaultSerializationOptions = memberSerializer.GetDefaultSerializationOptions(); if (memberDefaultSerializationOptions == null) { var message = string.Format( "A serialization options attribute of type {0} cannot be used when the serializer is of type {1}.", BsonUtils.GetFriendlyTypeName(this.GetType()), BsonUtils.GetFriendlyTypeName(memberSerializer.GetType())); throw new NotSupportedException(message); } memberSerializationOptions = memberDefaultSerializationOptions.Clone(); memberMap.SetSerializationOptions(memberSerializationOptions); } memberSerializationOptions.ApplyAttribute(memberSerializer, this); }
/// <summary> /// Applies the specified member map convention. /// </summary> /// <param name="memberMap">The member map convention.</param> public void Apply(BsonMemberMap memberMap) { IBsonSerializationOptions options = null; switch (memberMap.MemberInfo.MemberType) { case MemberTypes.Property: PropertyInfo propertyInfo = (PropertyInfo)memberMap.MemberInfo; if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?)) options = new DateTimeSerializationOptions(DateTimeKind.Local); break; case MemberTypes.Field: FieldInfo fieldInfo = (FieldInfo)memberMap.MemberInfo; if (fieldInfo.FieldType == typeof(DateTime) || fieldInfo.FieldType == typeof(DateTime?)) options = new DateTimeSerializationOptions(DateTimeKind.Local); break; default: break; } memberMap.SetSerializationOptions(options); }