是否可以使用protobuf http://code.google.com/p/protobuf/与继承的类?
我想做这样的事情
class Expr;
class AddExpr : Expr;
class CallFunc: Expr;
class FunctionBody{
repeatable Expr expr;
}
不在核心实现中 - 您可能希望使用封装来代替。
但是,如果您正在使用just protobuf网络 http://code.google.com/p/protobuf-net/,作为代码优先,我绕过它:
[ProtoInclude(1, typeof(AddExpr))]
[ProtoInclude(2, typeof(CallFunc))]
[ProtoContract]
class Expr {}
[ProtoContract]
class AddExpr : Expr {}
[ProtoContract]
class CallFunc: Expr {}
[ProtoContract]
class FunctionBody{
private List<Expr> expressions;
[ProtoMember(1)]
public List<Expr> Expressions {
get { return expressions ?? (expressions = new List<Expr>()); }
}
}
当然,我假设类中有一些额外的细节 - “按原样”你可以只使用枚举(其中is良好的支持)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)