6
我有一個庫,可以在CF.NET & .NET下運行,但兩者之間的序列化不同。因此,在.NET下生成的CF.NET下的XML文件是不可讀的,這對我來說是個大問題!XmlSerializer在.NET 3.5和CF.NET 3.5之間有所不同3.5
下面的代碼示例:
[Serializable, XmlRoot("config")]
public sealed class RemoteHost : IEquatable<RemoteHost>
{
// ...
}
public class Program
{
public static void Main()
{
RemoteHost host = new RemoteHost("A");
List<RemoteHost> hosts = new List<RemoteHost>();
hosts.Add(host);
XmlSerializer ser = new XmlSerializer(typeof(List<RemoteHost>));
ser.Serialize(Console.Out, hosts);
}
}
CF.NET XML:
<?xml version="1.0"?>
<ArrayOfConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<config Name="A">
</config>
</ArrayOfConfig>
.NET XML
<?xml version="1.0" encoding="ibm850"?>
<ArrayOfRemoteHost xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RemoteHost Name="A">
</RemoteHost>
</ArrayOfRemoteHost>
如何修改我的程序,以生成相同的XML?
Arghhhhhh ......這樣做的方式,我需要調整自己的所有商業模式......二進制輸出? – 2011-06-10 11:52:41
@Arnaud - 只是在序列化的時候添加一個包裝並不能真正改變整個模型。 – 2011-06-10 11:55:17
我需要將所有RemoteHost添加到MyRoot,如果我想序列化它們,將會看到... – 2011-06-10 12:05:18