protobuf-net 是否支持 [DataMember(Order=0)]? [英] Does protobuf-net support [DataMember(Order=0)]?

查看:27
本文介绍了protobuf-net 是否支持 [DataMember(Order=0)]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WCF 中使用 protobuf-net,发现 Order = 0 的数据成员没有出现在客户端上.这是我的数据合同 - ObjectId 在客户端始终为 Guid.Empty.

I am using protobuf-net with WCF, and finding that data members with Order = 0 are not showing up on the client. Here is my data contract - ObjectId is always Guid.Empty on the client side.

<DataContract()> _
Public Class ProtocolBufferDataContract

    <DataMember(Order:=0)> _
    Public Property ObjectId() As Guid

    <DataMember(Order:=1)> _
    Public Property Title() As String

End Class

我使用的是共享程序集机制,因此服务器和客户端都针对此类进行编译.如果我将订单更改为 1 和 2,则一切正常.为什么它不适用于 0?

I am using the shared-assembly mechanism, so both the server and client are compiled against this class. If I change the orders to 1 and 2, everything works. Why doesn't it work with 0?

推荐答案

奇怪 - 我原以为它会出错.Protobuf 密钥号始终为正数,因此 0 确实对 protobuf-net 无效.因此我希望它抛出!为此,它.也可以指定应用于 WCF 密钥的偏移量(主要用于代理类型).这可以通过 ProtoContractAttribute 完成(直接,或者在使用代理生成的部分类"中),或者可能(我没有检查过)在运行时通过 RuntimeTypeModel 应用.

Odd - I would have expected it to error with that. Protobuf key numbers are always positive, so 0 is indeed not valid for protobuf-net. Hence I would expect it to throw! For this reason, it. Is also possible to specify an offset to apply to WCF keys (intended primarily for use with proxy types). This can be done via ProtoContractAttribute (directly, or in a "partial class" if using proxy generation), or can probably (I haven't checked) be applied at runtime via RuntimeTypeModel.

这篇关于protobuf-net 是否支持 [DataMember(Order=0)]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆