Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

c# - Create MULTIPLE class files based on an 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.

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.

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...