How to quickly save/load class instance to file

后端 未结 7 1455
终归单人心
终归单人心 2020-12-09 05:33

I have several collections of classes/structs in my app.

The class is just a class with fields

class A
{
  public int somevalue;
  public string some         


        
7条回答
  •  感情败类
    2020-12-09 05:47

    There are many serializers:

    Part of .net framework

    • XmlSerializer (standardized format, slow and verbose)
    • BinarySerializer (proprietary format, medium speed, supports cyclic graphs, serializes fields instead of properties => annoying versioning)

    3rd party:

    • Json-Serializers (standardized format, text-based, shorter than xml)
    • ProtoBuf-Serializers (standardized format, binary, very fast)

    I'd probably use a ProtoBuf Serializer if the file may be binary, and a json serializer if it needs to be plain-text.

提交回复
热议问题