最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin15PV0评论

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?

Post a comment

comment list (0)

  1. No comments so far