更新时间:2023-11-24 20:57:28
您真正需要的是数据合同: http://msdn.microsoft.com/en-us /library/ms733127.aspx [ ^ ]。
请参阅我过去提倡这种方法的答案:
如何在表单应用程序中使用XML文件编写器和阅读器? [ ^ ],
创建属性文件... [ ^ ]。
这比这要好得多解决方案1中引用的解决方案。区别在于性能。 Data Contract序列化程序每种类型只执行一次反射。它使用System.Reflection.Emit
即时创建序列化程序集。如果您想自己开发类似的解决方案,那么您将面临非常了解CIL的需求,并且Emit代码很难调试。-SA
What you really need is Data Contract: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].
Please see my past answers advocating this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^].
This is much better then the solution referenced in Solution 1. The difference is performance. Data Contract serializer does the reflection only once per type. It creates a serialization assembly on the fly, usingSystem.Reflection.Emit
. If you wanted to develop similar solution by yourself, you would face with the need to know CIL very well, and Emit code is quite difficult to debug.—SA
找到一个比上面提供的好的
使用C#2.0中的通用类型将对象序列化和反序列化为XML [ ^ ]
Found a good one than offered above
Serialize and Deserialize Objects as XML using Generic Types in C# 2.0[^]