[펌] VS .Net에서 Macro를 이용하여 #Region 쉽게 추가하기

  • Post author:
  • Post category:
  • Post comments:0 Comments
  • Post last modified:February 8, 2020

출처 : 이런 저런 이야기~

아래 매크로가 #Region을 쉽게 넣어주는 매크로입니다.

매크로 등록은
VS 실행 후 프로젝트를 하나 여신 후 Tools – Macros – Macro IDE 를 실행한 후
MyMacro 폴더 안에 하나 만드시고… 아래 소스를 붙이시면 끝입니다.

단축키 없이 사용하기 불편하니

Tools – option – 환경 – 키보드

에서

다음 문자열을 포함하는 명령 표시에 매크로 이름을 넣으면 검색이 될껍니다.
선택한 후 바로 가기 키 누르기에 등록되지 않은 단축키를 하나 지정하시면 준비 끝!!

그 다음.. 소스에서 Region으로 지정하고 싶은 부분을 블럭 지정하시고
등록한 단축키를 누르면 대화창이 하나 뜹니다. Region 이름 넣는 부분
이름을 넣으시면 자동으로 Region으로 감싸 줍니다.
편하죠??

귀찮아서 그림은 뺐습니다. ^^’‘

출처 : http://blogs.msdn.com/powertoys/archive/2004/04/27/120775.aspx

Sub AddRegion()
  Dim CloseUndoContext As Boolean = False

  If DTE.UndoContext.IsOpen = False Then
      CloseUndoContext = True
      DTE.UndoContext.Open(“DevHawkAddRegionMacro”, False)
  End If

  Try
      Dim name As String = InputBox(“Enter the region name”)

      If (name.Trim().Length = 0) Then Exit Sub

      Dim sel As TextSelection = DTE.ActiveDocument.Selection

      Dim lTop = sel.TopPoint.Line
      Dim lBot = IIf(sel.BottomPoint.AtStartOfLine, sel.BottomPoint.Line – 1, sel.BottomPoint.Line)

      sel.MoveToLineAndOffset(lBot, 1)
      sel.EndOfLine()
      sel.NewLine()

      If DTE.ActiveDocument.Language = “CSharp” Then
        sel.Text = “#endregion”
      ElseIf DTE.ActiveDocument.Language = “Basic” Then
        sel.Text = “#End Region”
      Else
        Throw New System.Exception(“Invalid Language: ” + DTE.ActiveDocument.Language)
      End If

      sel.MoveToLineAndOffset(lTop, 1)
      sel.StartOfLine()

      If DTE.ActiveDocument.Language = “CSharp” Then
        sel.Text = “#region ” + name.Trim()
      ElseIf DTE.ActiveDocument.Language = “Basic” Then
        sel.Text = “#Region “”” + name.Trim() + “”“”
      Else
        Throw New System.Exception(“Invalid Language: ” + DTE.ActiveDocument.Language)
      End If

      sel.NewLine()
  Finally
      If CloseUndoContext Then DTE.UndoContext.Close()
  End Try
End Sub

 

 

 

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments