使用属性从xsd生成c#类

时间:2018-11-07 07:21:41

标签: c# xsd

我需要为一个旧项目提供支持,而我对xsd并没有太多经验。 项目在DataSet.xsd文件上运行xsd.exe,并生成包含通用c#类的DataSet.cs文件。

我需要在通用类的属性上添加一个标志或属性。我向名称为“ intradaySupport” 的xsd文件中添加了一个新属性。我尝试同时使用属性和注释,如下图所示,但生成了“ intradaySupport”

我应该如何更新DataSet.xsd文件,以便最终生成的类已标记有标志或属性。

enter image description here

enter image description here

链接上的全部内容只是将内容放入声明的文件中并运行xsd

CDBDataSet.xsd https://pastebin.com/e0DPAxgb
CustomFields.xsd https://pastebin.com/ScS3whrY

Specification.thrown

1 个答案:

答案 0 :(得分:0)

如果要在xsd中创建属性,则必须在xsd中指定<xs:attribute name="intradaySupport" type="xs:boolean" use="required"/>。它应该位于xs:sequence:

之后
            <xs:element name="AccountType">
                <xs:complexType>
                    <xs:sequence>                          
                        <xs:element name="Account_x0020_type" type="string12" minOccurs="0"  />
                        <xs:element name="Description" type="string40" minOccurs="0" >
                        ...
                        <xs:element name="Not_x0020_used" type="string1" minOccurs="0" />
                    </xs:sequence>
                    <xs:attribute name="intradaySupport" type="xs:boolean" use="required"/>
                </xs:complexType>
            </xs:element>
            ...

使用xsd.exe / dataset它将在您的数据集中生成一个布尔列columnintradaySupport:

[global::System.Serializable()]
[global::System.Xml.Serialization.XmlSchemaProviderAttribute("GetTypedTableSchema")]
public partial class AccountTypeDataTable : global::System.Data.DataTable, global::System.Collections.IEnumerable {

    private global::System.Data.DataColumn columnintradaySupport;

    private global::System.Data.DataColumn columnAccount_type;
    ...
}