如何解决“算术运算导致溢出。”对于具有长值的枚举

问题描述 投票:1回答:1

假设我有一个枚举

public enum PricingFlags : long

其值为1000000000001000011111111110001000_2或4296080913。基本上是像这样的标志的集合

[Description("Aggregate")]
Aggregate = 1L << 7,

逻辑或运算。我正在使用2.3.1版。

我尝试在属性中添加EnumPassthru

[ProtoContract(ImplicitFields = ImplicitFields.AllPublic, EnumPassthru = true)]

或在protobuf规范中,

 RuntimeTypeModel.Default[typeof(PricingFlags)].EnumPassthru = true;

[谷歌搜索后,我发现https://github.com/protobuf-net/protobuf-net/issues/219告诉我,它应该可以工作,但是没有。我做错了吗?

protobuf-net
1个回答
0
投票

我今天的建议是:声明一个影子属性(也许是私有的),该影子属性将数据公开很长时间,并在代码中进行强制转换。

© www.soinside.com 2019 - 2024. All rights reserved.