2010-06-17 36 views
3

为了保持一致性,我们为很多对象模型使用代码生成,并且其中一个分支已经通过单独的生成模块为ProtocolBuffers生成.proto文件。但是,在这一点上,我很难理解如何在发生在对象上的时候实现这一代。protobuf-net中的列表<T>的.proto等效物是什么?

看起来这是可能通过合同:

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

但那个以外,我不能确定它是如何或是否有可能做到这只能从创建.proto文件/使用VS定制工具。有什么想法吗?

回答

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

给出:

message Foo { 
    repeated Bar Items = 1; 
} 

message Bar { 
} 

最后 - 如果你需要不同的输出时,XSLT是用户-editable。

+0

完美的作品,谢谢! (如果可能的话,我会再给你一个upvote,只是为了写图书馆) – 2010-06-17 22:52:05

相关问题