使用工作注释将 XSD 转换为 C# 的免费工具/扩展

Mir*_*rek 0 c# xsd xsd.exe xsd2code

是否有任何工具或版本的 XSD2Code 或 xsd.exe 可以生成 C# 实体以及 XSD2Code 的注释?

XSD2Code 和 xsd.exe 都忽略注释(对于 XSD2Code,EnableSummaryComment 效果不佳),我不想花时间分析和更改它们背后的源代码...有谁知道是否有完整的注释工作和自由的选择?

小智 5

XmlSchemaClassGenerator支持元素、属性和类型的注释。它还可以不受限制地生成 XML 文档,而且它是开源的。完全披露:我是主要作者。

/// <summary>
/// <para>Complex root type.</para>
/// <para>Information root.</para>
/// </summary>
[System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "1.0.0.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute("root", Namespace="http://example.org/annotations")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute("root", Namespace="http://example.org/annotations")]
public partial class Root
{

    /// <summary>
    /// <para>
    ///            Test data in element.
    ///          </para>
    /// <para xml:lang="en">Minimum length: 1.</para>
    /// <para xml:lang="en">Maximum length: 50.</para>
    /// </summary>
    [System.ComponentModel.DataAnnotations.MinLengthAttribute(1)]
    [System.ComponentModel.DataAnnotations.MaxLengthAttribute(50)]
    [System.Xml.Serialization.XmlElementAttribute("TestElement", Namespace="http://example.org/annotations")]
    public string TestElement { get; set; }

    /// <summary>
    /// <para>
    ///          Optional test data in attribute.
    ///        </para>
    /// <para xml:lang="en">Minimum length: 1.</para>
    /// <para xml:lang="en">Maximum length: 50.</para>
    /// </summary>
    [System.ComponentModel.DataAnnotations.MinLengthAttribute(1)]
    [System.ComponentModel.DataAnnotations.MaxLengthAttribute(50)]
    [System.Xml.Serialization.XmlAttributeAttribute("TestAttribute", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string TestAttribute { get; set; }
}
Run Code Online (Sandbox Code Playgroud)