I have a custom List which carries some attributes I need to serialize along with its containing items.
However, as soon as I add a ProtoContract attribute to my custom list, its items dont get serialized anymore.
Example:
[ProtoContract]
public class MyCollection : List<string> {
[ProtoMember(1)]
public string MyAdditionalField;
}
Is this not supposed to work out of the box?
The only possible workaround I can think of is using a surrogate for the custom list which contains a separate List which then contains all the data. However, we are dealing with quite a lot of custom Lists… so this would be an inefficient approach.
Thank you,
TH
In common with
XmlSerializerandTypeDescriptor(and possiblyDataContractSerializer– I haven’t checked), there is a strong divide between is a list vs contains a list. If something is a list, it doesn’t have values itself.The preferred layout there would be to either have a list or values.
At the protocol level, there is simply no way of representing that, as this is just
repeated string {name} = {field}– there is simply nowhere forMyAdditionalFieldto go.(update); tested, and indeed
XmlSerializerbehaves the same:DataContractSerializerhated it more, throwing: