【发布时间】:2011-12-14 05:09:09
【问题描述】:
我有一个实现 IBsonSerializer 的类:
public class PersistentObject : IBsonSerializer
{
public object Id { get; set; }
public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
{
throw new NotImplementedException();
}
public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
{
throw new NotImplementedException();
}
public bool GetDocumentId(object document, out object id, out Type idNominalType, out IIdGenerator idGenerator)
{
throw new NotImplementedException();
}
public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
throw new NotImplementedException();
}
public void SetDocumentId(object document, object id)
{
throw new NotImplementedException();
}
}
是否可以使用 WCF Serializer 实现 Serialize 和 Deserialize 方法?
【问题讨论】:
-
我不明白。 WCF 序列化程序应该与外部(您的应用程序与另一个应用程序)对话,而 BsonSerializer 应该只与数据库对话。您是否正在尝试构建一个适配器,以便您可以将 WCF“翻译”为 MongoDB 连接?
-
我认为 BsonSerializer 使用 JsonSerializer 或者将对象序列化为 json 格式,对吗?所以如果它是正确的,是否可以使用 DataContractSerializer 来序列化对象?
-
我不详细了解
DataContractSerializer,但我会从不同层面解决问题。您将需要某种控制器来管理其间的应用程序逻辑、验证和授权。为什么需要DataContract serializer顺便说一句?您正在构建 REST API 吗? -
感谢mnemosyn,我想序列化一个具有双向关系的类。 BsonSerializer 做不到,但 DataContract 序列化器可以!那么解决办法是什么?
-
我认为这归结为您在这里提出的同一个问题:stackoverflow.com/questions/8461996/…
标签: c# mongodb serialization