从C#类文件生成.xsd,然后从它生成的.xsd文件生成类

时间:2017-11-09 22:26:37

标签: c# xsd

我们丢失了所有.xsd文件,只留下了C#类文件。我正在使用xsd.exe从C#类文件生成.xsd文件,但是当我使用xsd.exe从这些生成的.xsd文件生成回C#类时,新的C#类文件与原始文件不同。

为了说明我的问题,我简化了以下代码:

VisualStuio 2008

项目名称:web,项目类型:C#类库

构建输出:web.dll

2个源文件:

文件#1:Response.cs(包含基类)

    namespace VWS.Types
{
    using System.Xml.Serialization;

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    //[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
    public partial class Response
    {

    }

}

文件#2:ResponseTSIRetrieveList.cs

    namespace VWS.Types
{
    using System.Xml.Serialization;


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    //[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
    public partial class ResponseTSIRetrieveList : Response
    {


    }
}

步骤1:从ResponseTSIRetrieveList类生成.xsd文件:

       xsd.exe -t:ResponseTSIRetrieveList web.dll

      schema0.xsd file is generated.

步骤2:从.xsd文件生成C#类:

    xsd.exe -c schema0.xsd        

这是生成的C#文件:

    using System.Xml.Serialization;

// 
// This source code was auto-generated by xsd, Version=2.0.50727.1432.
// 


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=true)]
public partial class ResponseTSIRetrieveList : Response {
}

/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ResponseTSIRetrieveList))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class Response {
}

如您所见,基类和派生类都在同一个文件中生成。我怎么能避免这个?

提前多多感谢

0 个答案:

没有答案
相关问题