gpt4 book ai didi

.Net xsd.exe 工具不会生成所有类型

转载 作者:行者123 更新时间:2023-12-04 11:17:25 25 4
gpt4 key购买 nike

出于某种原因,MS .Net (v3.5) 工具 - xsd.exe 在没有在任何元素中使用时不会生成类型。

例如

XSD 文件(我加入了 complex 元素以避免此警告 - “警告:无法生成类,因为找不到具有复杂类型的顶级元素。”):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:simpleType name="EnumTest">
<xs:restriction base="xs:string">
<xs:enumeration value="item1" />
<xs:enumeration value="item2" />
<xs:enumeration value="item3" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="myComplexType">
<xs:attribute name="Name" use="required" type="xs:string"/>
</xs:complexType>
<xs:element name="myElem" type="myComplexType"></xs:element>
</xs:schema>

当我通过 xsd.exe 运行此程序时

xsd /c xsdfile.xsd



我在生成的 cs 文件中没有看到 EnumTest。

笔记;尽管我在这里不使用枚举,但在我的实际项目中,我有这样的情况,我们将枚举的字符串值作为输出发送。

如何强制 xsd 工具包含这些?还是我应该切换到其他工具?

我在 Visual Studio 2008 中工作。

最佳答案

我不得不得出结论,这是该工具的一个愚蠢的缺点。也许给一个开关来打开这种行为。由于没有这种行为,我被迫在 xsd 之外创建类型并创建碎片化代码。

这是我个人的观点,我很确定还有其他人会分享相同的观点。

关于.Net xsd.exe 工具不会生成所有类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2142197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com