111,096
社区成员




public List<XMLSystemChild> GetChildren
{
get { return m_oChildren; }
set { m_oChildren = value; }
}
<XMLSystemChild xsi:type="XMLChild" ID="XMP_3" TagName="test5">
<Extent>
<Max X="1" Y="1" Z="1" />
</Extent>
<PersistentID />
<GenericAttributes Number="1" Set="test3">
<GenericAttribute Name="test2" Format="string" Value="2" />
</GenericAttributes>
<XMLSystemChild xsi:type="XMLChildEx" ID="XMP_1" TagName="test">
<Extent>
<Max X="1" Y="1" Z="1" />
</Extent>
<PersistentID />
<GenericAttributes Number="1" Set="test3">
<GenericAttribute Name="test2" Format="string" Value="2" />
</GenericAttributes>
</XMLSystemChild>
</XMLSystemChild>
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
class Program
{
static void Main()
{
My my = new My()
{
Name = "Minion",
Pets = new List<Pet>() { new Dog(), new Cat() }
};
XmlSerializer serializer = new XmlSerializer(typeof(My));
using (StringWriter sw = new StringWriter())
{
serializer.Serialize(sw, my);
string xml = sw.ToString();
/*
<My xmlns:xsd="...">
<Name>Minion</Name>
<Pets>
<Dog />
<Cat />
</Pets>
</My>
*/
}
}
}
public class My
{
public string Name { get; set; }
[XmlArrayItem("Dog", Type = typeof(Dog))]
[XmlArrayItem("Cat", Type = typeof(Cat))]
public List<Pet> Pets { get; set; }
}
public class Pet { }
public class Dog : Pet { }
public class Cat : Pet { }