region java_Java相当于C#中的#region

有一些选择可以实现相同,遵循以下几点 .

1)打开宏浏览器:

2)创建新宏:

3)将其命名为“OutlineRegions”(或任何你想要的)

4)右键单击“OutlineRegions”(在Macro Explorer上显示)选择“编辑”选项并将以下VB代码粘贴到其中:

Imports System

Imports EnvDTE

Imports EnvDTE80

Imports EnvDTE90

Imports EnvDTE90a

Imports EnvDTE100

Imports System.Diagnostics

Imports System.Collections

Public Module OutlineRegions

Sub OutlineRegions()

Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection

Const REGION_START As String = "//#region"

Const REGION_END As String = "//#endregion"

selection.SelectAll()

Dim text As String = selection.Text

selection.StartOfDocument(True)

Dim startIndex As Integer

Dim endIndex As Integer

Dim lastIndex As Integer = 0

Dim startRegions As Stack = New Stack()

Do

startIndex = text.IndexOf(REGION_START, lastIndex)

endIndex = text.IndexOf(REGION_END, lastIndex)

If startIndex = -1 AndAlso endIndex = -1 Then

Exit Do

End If

If startIndex <> -1 AndAlso startIndex < endIndex Then

startRegions.Push(startIndex)

lastIndex = startIndex + 1

Else

' Outline region ...

selection.MoveToLineAndOffset(CalcLineNumber(text, CInt(startRegions.Pop())), 1)

selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)

selection.OutlineSection()

lastIndex = endIndex + 1

End If

Loop

selection.StartOfDocument()

End Sub

Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer)

Dim lineNumber As Integer = 1

Dim i As Integer = 0

While i < index

If text.Chars(i) = vbCr Then

lineNumber += 1

i += 1

End If

i += 1

End While

Return lineNumber

End Function

End Module

5)保存宏并关闭编辑器 .

6)现在让我们为宏分配快捷方式 . 转到工具 - >选项 - >环境 - >键盘,在“显示命令包含”文本框中搜索宏(在文本框中输入:宏,它将显示宏名称,选择你的一个 . )

7)现在在“按快捷键”下的文本框中,您可以输入所需的快捷方式 . 我用Ctrl M N.

使用:

return

{

//Properties

//#region

Name:null,

Address:null

//#endregion

}

8)按保存的快捷键

见下面的结果:

c8gtK.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值