我試圖序列化一個對象到內存,將它作爲一個字符串傳遞給另一個進程,並反序列化它。XmlSerializer轉換換行
我發現XML序列化過程剝離了對象中字符串換行符的\ r。
byte[] b;
// serialize to memory.
using (MemoryStream ms = new MemoryStream())
{
XmlSerializer xml = new XmlSerializer(this.GetType());
xml.Serialize(ms, this);
b = ms.GetBuffer();
}
// I can now send the bytes to my process.
Process(b);
// On the other end, I use:
using (MemoryStream ms = new MemoryStream(b))
{
XmlSerializer xml = new XmlSerializer(this.GetType());
clone = (myObject)xml.Deserialize(ms);
}
如何序列化對象沒有它序列化到磁盤上就是這樣的,但沒有串重整新行?
究竟哪些換行符被剝離? –
在myObjcet中,我有幾個字符串,每個字符串都可以包含換行符。 – Jerry
另外,你是否可以控制正在序列化的類?這兩個進程是否都運行.NET?如果是這樣,你有更好的選擇。 –