我正在使用XSD在C#中定义我的DTO类型.我正在使用XSD.exe来生成XSD的类.
我有一个定义地址类型的Common.xsd,我想在多个类中使用它:
<xs:complexType name="Address">
<xs:sequence>
<xs:element name="Street1" type="xs:string"/>
<xs:element name="Street2" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="State" type="xs:string"/>
<xs:element name="Zip" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Address" type="mhm:Address"/>
Run Code Online (Sandbox Code Playgroud)
我在XSD公司中引用它:
<xs:include schemaLocation=".\Common.xsd"/>
<xs:complexType name="Company">
<xs:sequence>
<xs:element name="AdmCode" type="xs:string"/>
<xs:element name="CompanyCode" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
<xs:element ref="mhm:Address"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Company" type="mhm:Company"/>
Run Code Online (Sandbox Code Playgroud)
员工XSD:
<xs:include schemaLocation=".\Common.xsd"/>
<xs:complexType name="Employee">
<xs:sequence>
<xs:element name="EmployeeNumber" type="xs:int"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Address" type="mhm:Address"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Employee" type="mhm:Employee"/>
Run Code Online (Sandbox Code Playgroud)
我使用这个命令行生成类:
xsd .\XSD\Common.xsd /c /o:. /n:"DomainModel"
xsd .\XSD\Employee.xsd /c /o:. …Run Code Online (Sandbox Code Playgroud)