2010-06-17 34 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

相關問題