引用通用类型的XSD Gen类 [英] XSD Gen Classes That Reference a Common Type

查看:65
本文介绍了引用通用类型的XSD Gen类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XSD在C#中定义我的DTO类型。我正在使用XSD.exe来生成XSD的类。

I am using XSD's to define my DTO types in C#. I am using XSD.exe to gen the classes from the XSD's.

我有一个Common.xsd,它定义了一个地址类型,并且我想在一个以上的类型中使用它。类:

I have a Common.xsd that defines an Address type and I want to use this in more than one class:

  <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"/>

我在公司XSD中引用此地址:

I am referencing this in a company 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"/>

和一名员工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"/>

我使用以下命令行生成了类:

I gen the classes using this command line:

xsd .\XSD\Common.xsd /c /o:. /n:"DomainModel"
xsd .\XSD\Employee.xsd /c /o:. /n:"DomainModel"
xsd .\XSD\Company.xsd /c /o:. /n:"DomainModel"

当我编译项目时,我发现Address类型具有是在Company.cs类文件和Employee.cs类文件中生成的。

When I go to compile the project, I find that the Address type has been generated in both the Company.cs class file and the Employee.cs class file.

如何在Common.cs类文件中获取仅生成一次的地址类型

How can I get the Address type generated just once in the Common.cs class file and the Employee and Company types use this single Address type?

推荐答案

您可以使用 XSD.exe ,带有多个文件参数:

You can use XSD.exe with multiple file arguments:

xsd .\XSD\Common.xsd .\XSD\Employee.xsd .\XSD\Company.xsd /c /o:. /n:"DomainModel"

这篇关于引用通用类型的XSD Gen类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆