gpt4 book ai didi

c# - 在#endregion 处自动创建同名的#region

转载 作者:可可西里 更新时间:2023-11-01 08:39:40 30 4
gpt4 key购买 nike

我想知道是否有办法让#region Some Region #endregion Some Region。如果没有办法做到这一点,那么也许可以使用 Resharper?

希望大家清楚我要在这里实现的目标。

编辑:

<?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>

第二次编辑:它的工作,但只有当我制作插入片段时。从 intellisense 这使用我猜的其他一些片段。

那么有没有办法从智能感知而不是插入片段菜单添加我的区域?

最佳答案

如果你想要实现的是......

#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$ 标记操作完成后您希望光标停留的位置。

关于c# - 在#endregion 处自动创建同名的#region,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18122131/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com