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

Mar*_*ger 3 c# protocol-buffers protobuf-net

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

看起来这可以通过合同:

[ProtoMember(1)]
public List<SomeType> MyList {get; set;} 
Run Code Online (Sandbox Code Playgroud)

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

Mar*_*ell 6

repeated SomeType MyList = 1;
Run Code Online (Sandbox Code Playgroud)

此外 - 它不是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 { }
Run Code Online (Sandbox Code Playgroud)

得到:

message Foo {
   repeated Bar Items = 1;
}

message Bar {
}
Run Code Online (Sandbox Code Playgroud)

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