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

点点圈 提交于 2019-12-23 20:07:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3065993/whats-the-proto-equivalent-of-listt-in-protobuf-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!