I generated with xsd.exe a dataModel of an xsd. I would like to exchange the dataType[] with generic list => List<dataType>. I need to change the syntax automated because the dataModel classes are huge.

My first intention was to generate the correct code directly with xsd.exe. After some investigation I found out that this is not an option.

Then I tried to solve my problem with Regex but I was not lucky to find the right expression. Probably someone could help me out. The modification can be done directly in Visual Studio or if this is not working in Notepad++.

What I'm trying to do:

public dataType1[] dataType1 => public List<dataType1> dataType1
public dataType2[][]         => public List<List<dataType2>>
public dataType3[][][]       => public List<List<List<dataType3>>>

My approach with Regex in VS:

// Find with:

// Replace with:

My approach is unfortunately not working in one step. Additionally I would have to treat 1 to n [] separated. Finally I have to delete all [] with find/replace what could lead to errors.

Could someone help me out with a one step solution? Either with Regex or probably with something different. Important for me would be a solution which I can deploy fast and easy after the creation of the dataModel.

1 Answers

Julio On Best Solutions

You may solve this with nodepad++ macros.

  1. Click on Start recording macro button

  2. Press Control + H to launch Search & Replace

  3. Find what: (?<=\s)([<>A-Za-z_0-9]+)\[\]

    Replace by: List<$1>

    Replace all

  4. Without closing the search dialog click on Find Next

  5. Click on Stop recording macro button.

  6. Now go to some file you want to process

  7. Click on Run a macro multiple times button

  8. Select Run until the end of file

  9. Run

NOTE: Once you have recorded a macro, you can 'save' it for later reuse. Once saved It will be available across notepad++ restarts.