C# Object Binary Serialization

前端 未结 6 1732
-上瘾入骨i
-上瘾入骨i 2020-12-05 02:17

I want to make a binary serialize of an object and the result to save it in a database.

Person person = new Person();
person.Name = \"something\";

MemoryStr         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 02:59

    Have you not looked into converting the memorystream into a base64hex string to be put into the database?

     byte[] mStream = memorystream.ToArray();
     string sConvertdHex = System.Convert.ToBase64String(mStream)
    

    Then you can dump the contents sConvertdHex to the database. To deserialize it you need to do the reverse

     byte[] mData = System.Convert.FromBase64String(...)
    

    then deserialize mData back to your object.

提交回复
热议问题