how to generate List instead of Array in C# with xsd.exe

Gero picture Gero · Mar 13, 2013 · Viewed 12.8k times · Source

I have an XML schema .xsd and generate with xsd.exe tool my file with all the c# classes. If I have a sequence of elements within an XML tag, that would be represented in C# with an Array. The FAIL is obvious. How can I generate Lists instead of Arrays?

Instead of fixed size arrays in a class, I would like to use Lists.

Book [] books = new Book[someFixSize];

List<Book> books =  new List<Book>();

I have seen some older (very old) questions about this, but none of them provided a satisfied solution :/

This is the latest useful hint: http://www.stefanbader.ch/xsdcsarr2l-exe-refactor-xsd-array-to-list/

Answer

EvilBad picture EvilBad · Mar 15, 2013

I run into the same problem trying to use the svcutil without having the contracts, for that reason I wrote the xsdcsarr2l tool. If you are interested I take the time and upload a newer version where at least the list variables are initialized automatically. On the other hand, the project is light enough, that you can take the source and improve it yourself by using the NRefactory classes.