[C#] [VS] Snippets快捷代码块之 Region
代码长了,阅读起来不方便,
于是,C#中我们经常会用 region
来折叠代码块。
在VS中,输入
#region
, 点Tab,会自动生成如下:
#region MyRegion
#endregion
修改下代码块的名字:RegionName
在中间填自己的代码/方法
#region RegionName
//...
// long c# code here
//...
#endregion
region
开始处会出现一个 折叠/展开 的 -/+
符号。
当分块多了,甚至嵌套起来,
会出现一堆#endregion
莎莎不知道自己在哪儿的情况。
//...
#endregion
#endregion
#endregion
#endregion
#endregion
//...
不知道为什么VS
默认不带,
个人觉得还是在#endregion
处也加上名字比较好,
所以,找到 region 快捷代码块的定义文件,修改如下:
(在 endregion 后面加上$name$
即可)
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>#region</Title>
<Shortcut>#region</Shortcut>
<Description>#region に対するコード スニペット</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>領域の名前</ToolTip>
<Default>MyRegion</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[#region $name$
$selected$ $end$
#endregion $name$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
文件位置在这:pp_region.snippet
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC#\Snippets\1041\Visual C#
作者:码路工人
公众号:码路工人有力量(Code-Power)
欢迎关注个人微信公众号 Coder-Power
一起学习提高吧~
![](https://gitee.com/Coding-Worker/picture/raw/master/2021-1-5/1609860559027-qrcode_for_gh_e1903e0c25a7_258.jpg)
posted on 2019-10-18 15:40 CoderMonkey 阅读(409) 评论(0) 编辑 收藏 举报