你在Visual Studio中发现过哪些宏可以用于代码操作和自动化?
这是我的宏,用于关闭解决方案,删除IntelliSense文件并重新打开解决方案。如果你在使用本地C++工作,则非常重要。
Sub UpdateIntellisense()
Dim solution As Solution = DTE.Solution
Dim filename As String = solution.FullName
Dim ncbFile As System.Text.StringBuilder = New System.Text.StringBuilder
ncbFile.Append(System.IO.Path.GetDirectoryName(filename) + "\")
ncbFile.Append(System.IO.Path.GetFileNameWithoutExtension(filename))
ncbFile.Append(".ncb")
solution.Close(True)
System.IO.File.Delete(ncbFile.ToString())
solution.Open(filename)
End Sub
''''replaceunicodechars.vb
Option Strict Off
Option Explicit Off
Imports EnvDTE
Imports System.Diagnostics
Public Module ReplaceUnicodeChars
Sub ReplaceUnicodeChars()
DTE.ExecuteCommand("Edit.Find")
ReplaceAllChar(ChrW(8230), "…") ' ellipses
ReplaceAllChar(ChrW(8220), "“") ' left double quote
ReplaceAllChar(ChrW(8221), "”") ' right double quote
ReplaceAllChar(ChrW(8216), "‘") ' left single quote
ReplaceAllChar(ChrW(8217), "’") ' right single quote
ReplaceAllChar(ChrW(8211), "–") ' en dash
ReplaceAllChar(ChrW(8212), "—") ' em dash
ReplaceAllChar(ChrW(176), "°") ' °
ReplaceAllChar(ChrW(188), "¼") ' ¼
ReplaceAllChar(ChrW(189), "½") ' ½
ReplaceAllChar(ChrW(169), "©") ' ©
ReplaceAllChar(ChrW(174), "®") ' ®
ReplaceAllChar(ChrW(8224), "†") ' dagger
ReplaceAllChar(ChrW(8225), "‡") ' double-dagger
ReplaceAllChar(ChrW(185), "¹") ' ¹
ReplaceAllChar(ChrW(178), "²") ' ²
ReplaceAllChar(ChrW(179), "³") ' ³
ReplaceAllChar(ChrW(153), "™") ' ™
''ReplaceAllChar(ChrW(0), "�")
DTE.Windows.Item(Constants.vsWindowKindFindReplace).Close()
End Sub
Sub ReplaceAllChar(ByVal findWhat, ByVal replaceWith)
DTE.Find.FindWhat = findWhat
DTE.Find.ReplaceWith = replaceWith
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
DTE.Find.MatchCase = False
DTE.Find.MatchWholeWord = False
DTE.Find.MatchInHiddenText = True
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
DTE.Find.Execute()
End Sub
End Module
当你需要进行任何类型的数据输入并希望一次性转义所有内容时,这将非常有用。
我正在使用Jean-Paul Boodhoo的BDD宏。它会将方法签名的标题行中的空格字符替换为下划线。这样,我就可以像正常句子一样输入测试用例的名称,按下键盘快捷键,就能得到有效的方法签名。
你可能想要添加代码片段,它们有助于加快开发时间并提高生产力。
标准的VB代码片段随默认安装一起提供。C#代码片段必须单独下载并添加。(以下是链接)
就宏而言,我通常没有使用过任何宏,但是《Visual Studio 2005》书中有一些非常好的宏。
C#代码片段链接: http://www.codinghorror.com/blog/files/ms-csharp-snippets.7z.zip (Jeff Atwood提供了链接) 希望对你有所帮助。