protobuf-net 中 List 的 .proto 等价物是什么?

2024-03-23

为了保持一定的一致性,我们对许多对象模型使用代码生成,其分支之一是通过单独的生成模块为 ProtocolBuffers 生成 .proto 文件。但在这一点上,我很难理解当它发生时如何实现生成List<T> object.

看起来这可以通过合同实现:

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

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


repeated SomeType MyList = 1;

另外 - 它不是 100% 完美,但你可以尝试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 {
}

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

protobuf-net 中 List 的 .proto 等价物是什么? 的相关文章

随机推荐