如何映射系统枚举在Protobuf.Net [英] How to map System Enum's in Protobuf.Net

查看:302
本文介绍了如何映射系统枚举在Protobuf.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有型System.IO.FileAttribute(枚举)

I have a class which has a property of type System.IO.FileAttribute (enum)

在与protobuf网序列我得到的错误:

Upon serializing with protobuf-net I get the error:

No wire-value is mapped to the enum System.IO.FileAttributes.Hidden, System, Archive

怎么会去映射系统枚举的与会员合同?

How would I go about mapping system enum's to a Contract with Members?

推荐答案

这是 [国旗] 枚举,它并没有真正在protobuf的直接映射(由谷歌定义)。我只想重新公开为 INT

That is a [Flags] enum, which doesn't really have a direct map in protobuf (as defined by google). I would simply re-expose as int:

public FileAttributes Attributes {get;set;}

[ProtoMember(12)] // whavever
private int AttributesSerialized {
    get { return (int)Attributes; }
    set { Attributes = (FileAttributes)value; }
}

此外,IIRC,我已经codeD V2以这种方式操作的 [国旗] 自动,并有选择地允许直通枚举(治疗作为基础值自动)。

Additionally, IIRC, I have already coded v2 to operate this way on [Flags] automatically, and to optionally allow pass-thru of enums (to treat as the underlying value automatically).

这篇关于如何映射系统枚举在Protobuf.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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