How to map system enumeration in Protobuf.Net

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

After serializing with protobuf-net, I get an error:

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

How do I go about enumerating an enumerated type in a contract with members?

+3
source share
1 answer

This is a rename [Flags]that does not actually have a direct map in protobuf (as defined by google). I would simply overexpose as int:

public FileAttributes Attributes {get;set;}

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

In addition, IIRC, I already encoded v2 to work this way on [Flags]automatically and, possibly, allow pass-thru enumerations (process as a base value automatically).

+3
source

Source: https://habr.com/ru/post/1796498/


All Articles