List<T> 的 .proto 等价物是什么?在protobuf-net中? [英] What&#39;s the .proto equivalent of List&lt;T&gt; in protobuf-net?

查看:25
本文介绍了List<T> 的 .proto 等价物是什么?在protobuf-net中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了保持一致性,我们为许多对象模型使用代码生成,其中一个分支是通过单独的生成模块为 ProtocolBuffers 生成 .proto 文件.但此时,我对如何实现发生在 List 对象上的生成感到困惑.

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

但除此之外,我不确定如何或是否可以仅通过创建 .proto 文件/使用 VS 自定义工具来做到这一点.有什么想法吗?

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;

另外 - 它不是 100% 完美,但您可以尝试 GetProto():

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

给出:

message Foo {
   repeated Bar Items = 1;
}

message Bar {
}

最后 - 如果您需要不同的输出,xslt 是用户可编辑的.

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

这篇关于List<T> 的 .proto 等价物是什么?在protobuf-net中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆