I have a uint32 to serialize to MongoDB.
I used to be able to do this using the following code from https://jira.mongodb.org/browse/CSHARP-252
public class AlwaysAllowUInt32OverflowConvention : ISerializationOptionsConvention
{
public IBsonSerializationOptions GetSerializationOptions(MemberInfo memberInfo)
{
Type type = null;
var fieldInfo = memberInfo as FieldInfo;
if (fieldInfo != null)
{
type = fieldInfo.FieldType;
}
var propertyInfo = memberInfo as PropertyInfo;
if (propertyInfo != null)
{
type = propertyInfo.PropertyType;
}
if (type == typeof(uint))
{
return new RepresentationSerializationOptions(BsonType.Int32) { AllowOverflow = true };
}
else
{
return null;
}
}
}
However in the new MongoDB library the ISerializationOptionsConvention
and RepresentationSerializationOptions
do not exist. I've had a look and cannot see how to register a default ConventionPack (?) for allowing uint32 to overflow int32 on the new library.
How can I do this without adding a BsonRepresentation attribute to my POCO?
所有评论(0)