Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a List instead of an array in C# with xsd.exe

I have an XML schema .xsd file and generate my file with all the C# classes with the xsd.exe tool. 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/

like image 934
Gero Avatar asked Mar 13 '13 15:03

Gero


2 Answers

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.

like image 168
EvilBad Avatar answered Sep 17 '22 23:09

EvilBad


Try using svcutil.exe

svcutil /o:myFile.cs /ct:System.Collections.Generic.List myXsd.xsd
like image 29
CathalMF Avatar answered Sep 17 '22 23:09

CathalMF