protobuf-net can't send Negative number

牧云@^-^@ 提交于 2019-12-13 00:37:23

问题


    [Required]
    [DefaultValue(-1)]

    public int MvcUserId { get; set; }

when I set MvcUserId =-1; but I will get MvcUserId =0; if i use json serlize the object ,everything will be ok.


回答1:


You need to actually apply the default:

[Required]
[DefaultValue(-1)]
public int MvcUserId { get; set; } = -1;

Without that protobuf-net ignores the value on send (because it is the default), and on receive there is nothing to process. protobuf-net assumes that your code correctly applies the defaults.



来源:https://stackoverflow.com/questions/41692470/protobuf-net-cant-send-negative-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!