我们只要对前一个例子进行简单的修改就可以把我们的App改写成使用SoapFormatter。
1.对System..Runtime.Serialization.Formatters.Soap.dll的引用。(经过我的试验,如果在VS.NET下需要添加,用csc编译不需要)
2.将using语句中的一个using System.Runtime.Serialization.Formatters.Binary改为using System.Runtime.Serialization.Formatters.Soap
3.将所有BinaryFormatter替换为SoapFormatter
4.将生成数据文件扩展名改为.xml
最后的控制台输出与前面例子的一样。
附上修改后的程序:
序列化 - 使用SoapFormatterusing System;
序列化 - 使用SoapFormatter
using System.IO;
序列化 - 使用SoapFormatter
using System.Collections;
序列化 - 使用SoapFormatter
using System.Runtime.Serialization;
序列化 - 使用SoapFormatter
using System.Runtime.Serialization.Formatters.Soap;
序列化 - 使用SoapFormatter
序列化 - 使用SoapFormatter[Serializable]
序列化 - 使用SoapFormatter
public class Insect
}

附上打开VS.NET中打开Insect.XML的截图:
序列化 - 使用SoapFormatter

相关文章: