应用属性通过批处理文件属性get / set方法 [英] Apply attribute to property get/set methods via batch file

查看:227
本文介绍了应用属性通过批处理文件属性get / set方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图自动化使用.NET Framework的XSD太创建部分类的生成和清除。我的主要问题是,[System.Diagnostics.DebuggerStepThroughAttribute()]会影响我的部分类code以及自动生成的。我可以删除,我用它来创建文件相同的批处理文件有问题的属性。

不过,我不希望被踏入所有自动生成的文件的属性。我可以通过应用[System.Diagnostics.DebuggerStepThrough()的get和set方法进入每个属性停止调试器。我可以通过一个批处理文件做到这一点?无需安装/配置第三方脚本语言做文本处理?

示例属性与属性补充说:

 公共字符串FileFormatVersion
{
    [System.Diagnostics.DebuggerStepThrough()]
    获得{
    返回this.fileFormatVersionField;
    }
    [System.Diagnostics.DebuggerStepThrough()]
    组
    {
        this.fileFormatVersionField =价值;
    }
}

通过批处理文件链接删除线(需要清理的第一部分)
<一href=\"http://stackoverflow.com/questions/418916/delete-certain-lines-in-a-txt-file-via-a-batch-file\">http://stackoverflow.com/questions/418916/delete-certain-lines-in-a-txt-file-via-a-batch-file


解决方案

  SETLOCAL enabledelayedexpansion
设置OUTFILE = 1.复印%
德尔%OUTFILE%
FOR / Fdelims =%%倍In(%1)做(
    集线= %%点¯x
    如果行:!===获得{(
    回声[System.Diagnostics.DebuggerStepThrough ^(^)]≥&GT;%OUTFILE%
    )
    如果行:!===设置{(
    回声[System.Diagnostics.DebuggerStepThrough ^(^)]≥&GT;%OUTFILE%
    )
    呼应%% X'GT;&GT;%OUTFILE%

这是简单的,不会处理情况下,像已有的属性补充性质。它可能还呛code的一些台词,但我还没有找到一条线,确实还没有。

制造下面提到的变化,除了额外的回声压痕(只是看起来这个页面上丑陋的)。

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

解决方案

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).

这篇关于应用属性通过批处理文件属性get / set方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆