这并不完全是您正在寻找的,但它可能会让您接近您需要的结果。
这是一个 Visual Studio 2008 宏,它将查找类图生成的获取属性并将其替换为自动属性。
- 在 VS 中转到查看 -> 其他窗口 -> 宏资源管理器
- 右键单击“MyMacros”并选择“新建模块...”
- 给它起任何你想要的名字
- 右键单击它并选择“新建宏”
- 将此代码粘贴到
这是代码:
DTE.ExecuteCommand("Edit.Find")
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
DTE.Find.FindWhat = "<get$"
DTE.Find.MatchCase = False
DTE.Find.MatchWholeWord = False
DTE.Find.Backwards = False
DTE.Find.MatchInHiddenText = True
DTE.Find.Action = vsFindAction.vsFindActionFind
While DTE.Find.Execute() <> vsFindResult.vsFindResultNotFound
DTE.ActiveDocument.Selection.LineDown(True, 6)
DTE.ExecuteCommand("Edit.Delete")
DTE.ActiveDocument.Selection.Text = "get; set;"
End While
这几乎只是一个 hack,我不确定它是否适用于类设计器的所有输出,但到目前为止它在我的测试中有效,它肯定会节省一些击键。
希望能帮助到你!