概括
使用XmlSerializer该类时,使用以下方法序列化 a List<T>(其中 T 可以XmlSerializer毫无问题地序列化)XmlAttributeOverrides:
using xmls = System.Xml.Serialization;
...
xmls.XmlAttributeOverrides attributeOverrides = new xmls.XmlAttributeOverrides();
attributeOverrides.Add(typeof(T), new xmls.XmlAttributes()
{
XmlRoot = new xmls.XmlRootAttribute("foo")
});
attributeOverrides.Add(typeof(List<T>), new xmls.XmlAttributes()
{
XmlArray = new xmls.XmlArrayAttribute("foobar"),
XmlArrayItems = { new xmls.XmlArrayItemAttribute("foo") },
});
Run Code Online (Sandbox Code Playgroud)
将在最内部的异常处抛出以下 InvalidOperationExcpetion:
System.InvalidOperationException: XmlRoot and XmlType attributes may not be specified for the type System.Collections.Generic.List`1[[T, programname, Version=versionnumber, Culture=neutral, PublicKeyToken=null]].
Run Code Online (Sandbox Code Playgroud)
我对序列化程序的期望
<texparams>
<texparam pname="TextureMinFilter" value="9729"/>
<texparam pname="TextureMagFilter" value="9729"/>
</texparams>
Run Code Online (Sandbox Code Playgroud)
我现在能成功得到什么
<ArrayOfTextureParameter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<TextureParameter …Run Code Online (Sandbox Code Playgroud)