Apply attribute to get / set methods of a property through a batch file

I am trying to automate the generation and cleanup of partial classes created using the .net framework XSD. My main problem is that [System.Diagnostics.DebuggerStepThroughAttribute ()] affects the code in my partial class as well as the automatically generated one. I can remove the insult attribute in the same batch file that I use to create the files.

However, I do not want to enter into all the properties of the auto-generated file. I can stop the debugger from entering each property by applying [System.Diagnostics.DebuggerStepThrough ()] to the get and set methods. Can I do this through a batch file? without the need to install / configure a third-party scripting language for text processing?

Example property with added attributes:

public string FileFormatVersion { [System.Diagnostics.DebuggerStepThrough()] get { return this.fileFormatVersionField; } [System.Diagnostics.DebuggerStepThrough()] set { this.fileFormatVersionField = value; } } 

Link to delete lines through a batch file (the first part of the necessary cleaning) Delete specific lines in a txt file through a batch file

0
source share
2 answers
 setlocal enabledelayedexpansion set outfile=%1.copy del "%outfile%" for /f "delims=" %%x in (%1) do ( set line=%%x if "!line: =!"=="get{" ( echo [System.Diagnostics.DebuggerStepThrough^(^)]>>%outfile% ) if "!line: =!"=="set{" ( echo [System.Diagnostics.DebuggerStepThrough^(^)]>>%outfile% ) echo.%%x>>%outfile% ) 

This is simplistic and will not handle cases such as properties that have already added an attribute. It can also be choked with some lines of code, but I have not found a line yet.

[Edit] Made the changes mentioned below, with the exception of an additional indentation of the echo (it will just look ugly on this page).

+1
source

I know you want to use a .bat file, but I really think your best option is for python or another scripting language.

0
source

Source: https://habr.com/ru/post/911508/


All Articles