XSD.EXE 生成的代码问题:元素序列生成为数组 [英] Problem with Code Generated by XSD.EXE: Sequence of Elements is Generated as an Array

查看:34
本文介绍了XSD.EXE 生成的代码问题:元素序列生成为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 xsd.exe 从 XSD 生成 C# 代码

I am trying to generate C# code from an XSD using xsd.exe

这里是问题区域的片段

<xs:element name="EmailConfiguration" minOccurs="1" maxOccurs="1">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="DefaultSendToAddressCollection" minOccurs="0" maxOccurs="1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="EmailAddress" type="xs:string" minOccurs="1" maxOccurs="unbounded" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>

        </xs:sequence>
      </xs:complexType>
    </xs:element>

当前 DefaultSendToAddressCollection 被生成为字符串[]

Currently DefaultSendToAddressCollection is being generated as a string[]

如何更改 xsd,使其生成为强类型,并将电子邮件地址作为强类型的集合?

How can I change the xsd, so that it is generated as a strong type, and email addresses as a collection to the strong type?

问题更新:

还是 xsd.exe 被窃听了?

Or is xsd.exe bugged?

推荐答案

您已将 EmailAddress 指定为 xs:string 类型而不是复杂类型 - 因此, DefaultSendToAddressCollection 是一个字符串数组, 而不是对象的集合.

You've specified EmailAddress to be of type xs:string instead of a complex type - therefore, DefaultSendToAddressCollection is an array of strings, instead of a collection of objects.

如果您将 EmailAddress 更改为复杂类型,并为其指定一个 xs:string 类型的 xs:attribute 来存储地址,您将最终得到EmailAddress 对象的集合.

If you change EmailAddress to be a complex type, and give it an xs:attribute of type xs:string to store the address to, you will end up with a collection of EmailAddress objects.

<xs:element name="EmailConfiguration" minOccurs="1" maxOccurs="1">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="DefaultSendToAddressCollection" minOccurs="0" maxOccurs="1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="EmailAddress" minOccurs="1" maxOccurs="unbounded">
                  <xs:complexType>
                    <xs:attribute name="Address" type="xs:string" />
                  </xs:complexType>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>

这篇关于XSD.EXE 生成的代码问题:元素序列生成为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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