3

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

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?

Jafin
  • 4,153
  • 1
  • 40
  • 52

1 Answers1

3

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; }
}

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).

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900