Serialization byte array vs XML file

前端 未结 7 1914
礼貌的吻别
礼貌的吻别 2021-01-06 08:42

I am heavily using byte array to transfer objects, primitive data, over the network and back. I adapt java\'s approach, by having a type implement ISerializable, which cont

7条回答
  •  轮回少年
    2021-01-06 09:12

    Creating your own ISerializable interface when there's already one in the framework sounds like a bit of a recipe for disaster. At least give it a different name.

    You'll have a bit of a problem when it comes to reading - you won't have an instance to call the method on. You might want to make it a sort of "factory" instead:

    public interface ISerializationFactory
    {
        T ReadObjectData(Stream input);
        void WriteObjectData(Stream output);
    }
    

    As for XML vs binary... it entirely depends on the situation: how much data will there be, do you need backwards and forwards compatibility, does the XML serialization in .NET give you enough control already etc.

提交回复
热议问题