tags:

views:

214

answers:

2

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

However I don't want to be stepping into all of the autogenerated file's properties. I can stop the debugger from entering each property by applying [System.Diagnostics.DebuggerStepThrough()] to the get and set methods. Can I do this via a batch file? without needing to install/configure a third party scripting language to do the text processing?

Example property with attributes added:

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

Link to deleting lines via a batch file (first part of the needed cleanup) http://stackoverflow.com/questions/418916/delete-certain-lines-in-a-txt-file-via-a-batch-file

A: 

I know you'd like to use a .bat file but I really think python or another scripting language is your best bet here.

Mark P Neyer
If it was the only option perhaps, but adding an additional tool to the dev process for a tertiary priority task is a bit of overkill when not needed IMO.
Dan Neely
+1  A: 
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 won't handle cases like properties that already have the attribute added. It also might choke on some lines of code, but I haven't found a line that does yet.

[Edit] Made the changes mentioned below, except for the extra echo indentation (would just look ugly on this page).

JimG
The XSD tool's output is very circumscribed in format so I was able to dispense with two of your cases. I added 12 spaces into the echo's to properly indent the attributes, and changed the last echo to properly output blank lines instead of the text "ECHO is on".
Dan Neely
My revised version of your batch file (since I don't have the rep to edit your post directly).setlocal enabledelayedexpansionset outfile=%1.Xsd.csdel "%outfile%"for /f "delims=" %%x in (%1.Xsd.cs.temp) do ( set line=%%x if "!line: =!"=="get{" ( echo [System.Diagnostics.DebuggerStepThrough^(^)]>>%outfile% ) if "!line: =!"=="set{" ( echo [System.Diagnostics.DebuggerStepThrough^(^)]>>%outfile% ) echo.%%x>>%outfile%)
Dan Neely
ugh, that came out much less readable than I intended.
Dan Neely