我想知道是否有办法制作#region Some Region #endregion Some Region
。
如果没有办法做到这一点,那么也许可以使用 Resharper 来实现吗?
希望我在这里想要实现的目标很清楚。
Edit:
<?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>Code snippet for #region</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>Region name</ToolTip>
<Default>MyRegion</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[#region $name$
$selected$ $end$
#endregion $name$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
第二次编辑:这是工作,但只有当我插入片段时。从智能感知中,我猜这是使用其他一些片段。
那么有没有办法从智能感知而不是从插入片段菜单添加我的区域?
如果您想要实现的目标是...
#region MyRegion
//...lots of code...
#endregion // end of MyRegion
您可以使用所谓的“SurroundsWith”代码片段来完成此操作。这是我的图书馆中的一个片段......
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0"
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Enregions a block of code</Title>
<Author>GJV</Author>
<Shortcut>enr</Shortcut>
<Description>Surrounds a block of code with region directives</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>RegionName</ID>
<ToolTip>Region Name</ToolTip>
<Default>MyRegion</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[#region $RegionName$$end$
$selected$
#endregion // end of $RegionName$]]>
</Code>
</Snippet>
</CodeSnippet>
要在 Visual Studio 中使用它,请将代码片段放入 .snippet 文件中并将其保存在代码片段目录中,然后转到“工具”=>“代码片段管理器”=>“添加”。添加后,您可以使用标准 CTRK K+X 来访问它。
与区域的内置代码片段相比,这给您带来的唯一好处是可以灵活地添加尾随注释以指示区域的结束。您还可以通过添加其他扩展来进一步自定义它。
注意:标记 $end$ 标记操作完成时您希望光标停留的位置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)