acrilige
acrilige

Reputation: 2456

protobuf-net repeated field as ObservableCollection<T>

When I compile this sample .proto file with protobuf-net:

message A
{
   repeated float values = 1;
}

The generated file contains class which has List<Single> property. Is there any way to use ObservableCollection<Single> property instead of List<Single>? Actually, the reason is: I want to use generated class directly in WPF application, but it's a bit difficult to bind this property to somewhat because I will not see any changes in this case.

May be there is some work-around for this? Because otherwise i will have to make wraps for each class which is not very convenient.

EDIT: I can just replace all lists with observable collections inside of batch-file, for example, but will it lead to some problems? Or it is the real solution for this case?

Upvotes: 3

Views: 921

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063844

At the moment the code-gen tool is hard-coded to List<T>. Of course, the code-gen tool is also entirely optional - so one option is: don't work from the code-gen tool (it will work fine with hand-drawn DTOs). If you are happy to simply do an automated replace, that is fine - it won't upset protobuf-net at all. But if you do this lots, another option is to edit the csharp.xslt file in the code-generator's directory. This is an xsl-transform file that generates the code from an xml representation of the model. There are (IIRC) 3 occurrences of global::System.Collections.Generic.List that you can change to anything you like. You can either over-write csharp.xslt, or copy it into a new file (and edit that), and then just specify that as the transform when calling protogen.

Upvotes: 3

Related Questions