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++.
public dataType1[] dataType1 => public List<dataType1> dataType1
public dataType2[][] => public List<List<dataType2>>
public dataType3[][][] => public List<List<List<dataType3>>>
// Find with:
(?<=\s)[A-Za-z_0-9]+(?=(\[\]){1})
// Replace with:
List<$&>
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.
You may solve this with nodepad++ macros.
Click on Start recording macro
button
Press Control + H to launch Search & Replace
Find what: (?<=\\s)([<>A-Za-z_0-9]+)\\[\\]
Replace by: List<$1>
Replace all
Without closing the search dialog click on Find Next
Click on Stop recording macro
button.
Now go to some file you want to process
Click on Run a macro multiple times
button
Select Run until the end of file
Run
NOTE: Once you have recorded a macro, you can 'save' it for later reuse. Once saved It will be available across notepad++ restarts.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.