Reputation: 99
.Net
My protobuf file:
message Result{
repeated ListOfStrings lists = 1;
}
message ListOfStrings {
repeated string strings = 1;
}
And I have a class with this property:
public List<List<string>> ListOfLists { get; set; }
Protobuf compiler generates RepeatedField
collection and when I'm trying to pass this collection to ListOfLists.AddRange()
I get this error:
cannot convert from 'Google.ProtobufCollections.RepeatedField<gRPC.ListOfStrings>' to 'System.Collection.Generic.IEnumerable<System.Collections.Generic.List<string>>
How to deal with it?
Upvotes: 5
Views: 7989
Reputation: 9129
With the C# range operator you could simply write something like this:
List<TargetType> list = [.. result.Lists];
where result.Lists is of type RepeatedField
Upvotes: 1
Reputation: 1063864
A List<List<string>>
is not the same as a list of things that have strings. You will probably need:
foreach (var list in outerList) {
var inner = new ListOfStrings();
inner.Strings.AddRange(list);
obj.Lists.Add(inner);
}
Upvotes: 3