开发者

What's the .proto equivalent of List<T> in protobuf-net?

To keep some consistency, we use code generation for a lot of our object models, and one of the offshoots of that has been generating the .proto files for ProtocolBuffers via a separate generation module.开发者_如何学C At this point though, I'm stumped at how to implement the generation for when it happens upon a List<T> object.

It looks like this is possible via contracts:

[ProtoMember(1)]
public List<SomeType> MyList {get; set;} 

but outside of that, I'm not sure how or if it's possible to do this only from creating the .proto file/using the VS custom tool. Any thoughts?


repeated SomeType MyList = 1;

Also - it is not 100% perfect, but you can try GetProto():

class Program
{
    static void Main()
    {
        Console.WriteLine(Serializer.GetProto<Foo>());
    }
}
[ProtoContract]
public class Foo
{
    [ProtoMember(1)]
    public List<Bar> Items { get; set; }
}
[ProtoContract]
public class Bar { }

gives:

message Foo {
   repeated Bar Items = 1;
}

message Bar {
}

Finally - if you need different output, the xslt is user-editable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜