3

We've been using protobuf-net ProtoGen to generate C# .cs file from *.proto file. We would like instead of class to generate struct. e.g.

[DataContract]
public struct Entity1
{
    [ProtoMember(1)]
    public double Field1 { get; set; }

    [ProtoMember(2)]
    public string Field2 { get; set; }
}

I tried to extract protocol buffer using method Serializer.GetProto for class and struct type. It seems, that protocol buffer (.proto) doesn't recognize difference between the struct and class. So I imply, that could be a parameter in ProtoGen to choose between class/struct for generation from .proto. Does the feature exist or how could I solve generation of the struct from *.proto?

4

1 回答 1

1

目前,ProtoGen 只发出类;由于数据本质上是可变的,我会说这是合理的,但是 - 有两种选择:

  • 编辑csharp.xslt替换classstruct(或复制 csharp.xslt,并使用-t参数告诉它使用副本)
  • “按原样”使用它,并明智地使用ctrl+ h(我知道技术含量低;但它会起作用)
于 2013-08-21T14:46:21.983 回答