protobuf-net 无法发送负数 [英] protobuf-net can't send Negative number

查看:43
本文介绍了protobuf-net 无法发送负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    [Required]
    [DefaultValue(-1)]

    public int MvcUserId { get; set; }

当我设置 MvcUserId =-1;但我会得到 MvcUserId =0;如果我使用 json serlize 对象,一切都会好的.

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

推荐答案

你需要实际应用默认:

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

没有这个 protobuf-net 会忽略发送时的值(因为它是默认值),并且在接收时没有任何处理.protobuf-net 假设您的代码正确应用了默认值.

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.

这篇关于protobuf-net 无法发送负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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