简体   繁体   English

使用XSD.exe从具有IEnumerable而不是Array的架构生成类

[英]Using XSD.exe to generate classes from a Schema with IEnumerable instead of an Array

I am using XSD.exe to generate a set of .NET classes that will map to my XSD schema. 我正在使用XSD.exe生成一组.NET类,这些类将映射到我的XSD架构。 One thing I would like is to have repeated elements of a sequence mapped in the new classes as an IEnumerable instead of Array. 我想做的一件事是在新类中将序列的重复元素作为IEnumerable而不是Array进行映射。

Here is a snipped of the XSD schema: 以下是XSD模式的摘要:

<xs:element name="Locations">
    <xs:complexType>
      <xs:sequence>
         <xs:element name="Location" maxOccurs="unbounded">

This will generate my Locations class with a Location property which is of type Location[] . 这将生成具有Location属性的Locations类,该Location属性的类型为Location [] (An array). (数组)。

I would much rather it generate as IEnumerable<Location> . 我宁愿它生成为IEnumerable<Location> This would make using the generated classes much simpler. 这将使生成的类的使用更加简单。

Is it possible? 可能吗?

简而言之,不。请看一下xsd2code,它使您可以生成List<Location>

您可以使用xsd2code(尝试一下!),也可以使用“ svcutil.exe”而不是xsd.exe,如果我很好的话,可以将其应用于XSD,并允许传递这样的开关:/collectionType:System.Collections通用清单1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM