作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
Mongo 驱动程序的旧实现导致了这种代码:
public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType)
{
if (nominalType == typeof(T))
{
if (typeof(V) == typeof(string))
return _deSerializeFunc(bsonReader.ReadString());
else if (typeof(V) == typeof(int))
return _deSerializeFunc(bsonReader.ReadInt32());
else if (typeof(V) == typeof(double))
return _deSerializeFunc(bsonReader.ReadDouble());
else if (typeof(V) == typeof(decimal))
return _deSerializeFunc((decimal)bsonReader.ReadDouble());
}
return null;
}
新界面完全不同。我怎样才能开始用这个新界面实现以前的代码?
public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
{
最佳答案
在 .NET 驱动程序的 2.0 版本中,我们需要将更多信息传递给序列化程序。我们没有向方法中添加更多参数,而是将参数打包为两个新参数。 context 参数包含在整个序列化操作中应该保持不变的值,args 参数包含在序列化复杂类型时在每个级别更改的值。
移植到新设计应该相对容易:
关于实际类型,现在每个序列化程序都有责任确定实际类型(使用它想要的任何约定),并在实际类型与标称类型不同时查找并委托(delegate)给实际序列化程序。如果您正在序列化的类不是多态的,那么标称类型和实际类型无论如何总是相同的。
关于c# - 使用 Mongo 驱动程序升级 IBsonSerializer 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30328564/
Mongo 驱动程序的旧实现导致了这种代码: public object Deserialize(BsonReader bsonReader, Type nominalType, Type actua
我正在通过实现接口(interface)来实现自定义序列化程序:在 MongoDB C# 驱动程序版本 2.2.2 上定义的 IBsonSerializer。 Serialize 和 Deserial
在搜索解决方案时,我得到了 this和 this但我不清楚这个概念,所以无法实现:(。当我尝试更新数据库中的值(特别是日期时间对象)时会发生此错误。以下是我正在使用的代码:- var upd
我是一名优秀的程序员,十分优秀!