您可以使用
XSD.exe(可从Visual Studio安装中获得。)
public sealed class Configuration{ public string Name { get; set; } public Levels Level { get; set; } public ConfigurationSpec Spec { get; set; }} public abstract class ConfigurationSpec { } public class ConfigurationSpec1 { }public class ConfigurationSpec2 { }结果是
<?xml version="1.0" encoding="utf-8"?><xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Levels" type="Levels" /> <xs:simpleType name="Levels"> <xs:restriction base="xs:string"> <xs:enumeration value="Easy" /> <xs:enumeration value="Medium" /> <xs:enumeration value="Hard" /> </xs:restriction> </xs:simpleType> <xs:element name="Configuration" nillable="true" type="Configuration" /> <xs:complexType name="Configuration"> <xs:sequence> <xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" /> <xs:element minOccurs="1" maxOccurs="1" name="Level" type="Levels" /> <xs:element minOccurs="0" maxOccurs="1" name="Spec" type="ConfigurationSpec" /> </xs:sequence> </xs:complexType> <xs:complexType name="ConfigurationSpec" abstract="true" /> <xs:element name="ConfigurationSpec" nillable="true" type="ConfigurationSpec" /> <xs:element name="ConfigurationSpec1" nillable="true" type="ConfigurationSpec1" /> <xs:complexType name="ConfigurationSpec1" /> <xs:element name="ConfigurationSpec2" nillable="true" type="ConfigurationSpec2" /> <xs:complexType name="ConfigurationSpec2" /></xs:schema>
您要做的就是编译程序集,并
XSD.exe以程序集的路径作为参数运行。
XSD.exe /?也具有所有参数的列表。
例:
XSD.exe C:DevProject1BinDebuglibrary.dll



