views:

70

answers:

1

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

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?

+5  A: 
repeated SomeType MyList = 1;

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

gives:

message Foo {
   repeated Bar Items = 1;
}

message Bar {
}

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

Marc Gravell
Works perfectly, thanks! (If it were possible, I'd give you another upvote just for writing the library)
Marc Bollinger