简体   繁体   English

如何从 XSD 以编程方式生成 .NET 类? (就像 xsd.exe 那样)

[英]How to programmatically generate .NET classes from XSD? (Like xsd.exe do)

我想以 xsd.exe 方式而不是linq toxsd 方式生成类。

Look at the System.Xml.Serialization.XmlCodeExporter class.查看System.Xml.Serialization.XmlCodeExporter类。

UPDATE (in case John Saunders didnt bother reading further)更新(以防约翰桑德斯没有进一步阅读)

"Xsd.exe uses XmlCodeExporter to generate classes from XML Schema Definition (XSD) documents." “Xsd.exe 使用 XmlCodeExporter 从 XML 架构定义 (XSD) 文档生成类。”

Try Xsd2Code试试Xsd2Code

Seems to be the best free/Open source tool out there.似乎是最好的免费/开源工具。

Good integration with VS2010与 VS2010 的良好集成

It's working great for me.它对我很有用。

You can call xsd.exe from your code using Process Class .您可以使用Process Class从您的代码中调用 xsd.exe 。 I did it once and its fast and straightforward.我做过一次,它快速而直接。 You won't need to bored much :).你不需要太无聊:)。

Which part of the process do you not know how to do?流程的哪一部分不知道怎么做?

You can load one or more instances of the XmlSchema class into an XmlSchemaSet .您可以将XmlSchema类的一个或多个实例加载到XmlSchemaSet 中 This will allow you to programmaticly examine all parts of the schema and other schemas it may reference.这将允许您以编程方式检查架构的所有部分以及它可能引用的其他架构。 You can use this information to generate code, either as text that will later need to be compiled, or else using the CodeDOM.您可以使用此信息生成代码,或者作为稍后需要编译的文本,或者使用 CodeDOM。 See Dynamic Source Code Generation and Compilation .请参阅动态源代码生成和编译


If you are generating code in the context of Visual Studio, then I'd suggest you do so via T4 Templates.如果您是在 Visual Studio 的上下文中生成代码,那么我建议您通过 T4 模板来进行。 See Generating Artifacts By Using Text Templates .请参阅使用文本模板生成工件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM