【发布时间】:2010-06-23 08:51:42
【问题描述】:
我已经阅读了很多关于 protobuf-net 中继承特性的问题。 我只是想知道是否可以像使用 [ProtoContract]、[ProtoMember] 一样使用 [DataContract]、[DataMember]。为什么我不能使用 [KnowType] 而不是使用 [ProtoInclude]?
我提出这个问题是因为我已经使用 [DataContract],[DataMember] 进行 protobuf-net 的序列化。无需添加“Protobuf-net”。它仅使用“System.Runtime.Serialization”。
但是...现在如果我的类需要从某个类继承,我是否必须为 [ProtoInclude] 属性添加“Protobuf-net”?例如,
using System.Runtime.Serialization;
namespace test
{
[DataContract]
/// [KnowType(typeof(SomeClass))]
/// or
/// [ProtoInclude(100,typeof(SomeClass))]
public class BaseClass
{
//...
[DataMember(Order=1)]
public string BlahBlahBlah {get; set;}
}
[DataContract]
public class ChildClass1 : BaseClass
{
//...
[DataMember(Order=1)]
public string BlahBlahBlah {get; set;}
}
}// end namespace
最后,我想知道我是否有 100 个子类,在基类中添加 100 个 [ProtoInclude] 标签会不会让自己发疯?
感谢任何帮助
Ve
【问题讨论】:
-
请注意,这在 v2 中不再适用
-
@Marc;谢谢更新。那我试试v2吧。
标签: protobuf-net