c# - protobuf-net serialize object array when it only contains known types (int, string, decimal, etc.) - Stack Overflow

admin2025-04-06  3

Maybe this is a nobrainer.

I have a tabular data structure where each row is represented by an object[]. The data structure implements ITypedList so I can even tell the exact type of each object in the array.

What would be the best way to use protobuf-net to serialize this object array?

Obviously I cannot just adorn it with [ProtoMember(1)].

Should I create my own value class like so

[ProtoContract]
public class ValueWrapper
{
    [ProtoMember(1)] public int IntValue {get;set;}
    [ProtoMember(2)] public string StringValue {get;set;}
    [ProtoMember(3)] public bool BoolValue {get;set;}

    [ProtoMember(4)] public AvailableTypes Type {get;set;}
}

and replace object[] with ValueWrapper[] or is there an easier, more streamlined (and less allocation-heavy?) way to do it?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1743900947a223304.html

最新回复(0)