private static Type GetRawValueType(BsonValue elementValue, bool isKey = false)
{
Type elementType;
switch (elementValue.BsonType)
{
case BsonType.DateTime:
elementType = typeof(DateTime);
break;
default:
elementType = BsonTypeMapper.MapToDotNetValue(elementValue).GetType();
break;
}
if (!isKey && elementType.IsValueType)
{
elementType = typeof(Nullable<>).MakeGenericType(elementType);
}
return elementType;
}