基于XSD创建多个类文件 [英] Create MULTIPLE class files based on an XSD

查看:115
本文介绍了基于XSD创建多个类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能正在尝试使用XSD工具无法实现的功能,但是我想问一问,然后再继续使用简单的解决方案。

I may be attempting something that is not possible with the XSD tool but I wanted to ask before moving on to a simpler solution.

我有一个XSD文件,具有多个元素(和多个复杂类型),这些元素将在一个代码文件中生成多个类(我不喜欢这样)。为了从XSD工具生成干净且可读的类文件,我希望将每个元素放置在单独的代码文件中,而不是将所有元素都作为部分类放置在一个代码文件中。

I have an XSD file that has multiple elements (and multiple complex types) that will generate multiple classes in one code file (I do not like this). For the sake of having clean and readable class files generated from the XSD tool, I would like for each element to be placed in a seperate code file, not all placed in one code file as partial classes.

有人知道怎么做吗?还是我唯一的解决方案,用于将XSD分解为架构中每个xml元素的一个架构?

Does anyone know how to do this? Or is my only solution for this breaking the XSD into one schema for each of the xml elements in the schema?

MSDN文章 http://msdn.microsoft.com/en-us/library/x6c1kb0s(v = VS .100).aspx 不提供指定是否可以执行此操作的语言。

The MSDN article http://msdn.microsoft.com/en-us/library/x6c1kb0s(v=VS.100).aspx does not provide language that specifies whether or not this can be done.

在此先感谢您提供任何答案或评论。

Thanks in advance for any answers or comments.

推荐答案

这不能直接回答您的问题,但我想提出一些建议:

This doesn't answer your question directly, but I wanted to throw a couple things out:

我通常发现将生成的代码分开会适得其反。我总是喜欢通常遵循每个文件一个类的规则,但是在这里我例外,因为我经常处理非常大的模式。即使在他们自己的目录中,当我生成新版本的代码时,我也不必将文件分散到数十个(数百个)。我发现将所有生成的代码可扩散到一个文件中非常方便。

I generally find it counter-productive to separate generated code. I always like to generally follow the "one class per file" rule, but I make an exception here, because I often deal with very large schemas. Even in their own directory, I don't want to have to diff tens (to hundreds) of files when I generate a new version of the code. I find it very convenient to have all the generated code diffable in one file.

现在,提供一种可能的解决方案- Resharper 能够将所有类从文件中拉出,并将它们放入自己的文件中。如果在解决方案资源管理器中右键单击文件,则可以说 Refactor→将类型移到匹配文件中 ... 。当然,这不像以这种方式生成它那样方便,但是我不知道可以做到这一点的工具。

Now, to offer a possible solution - Resharper has the ability to pull all the classes out of a file and put them in their own files. If you right click the file in the solution explorer, you can say Refactor → Move types into matching files.... Of course, this isn't anywhere near as convenient as just generating it this way, but I don't know of a tool that will do that.

这篇关于基于XSD创建多个类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆