在#endregion自动创建具有相同名称的#region

Har*_*9pl 13 .net c# resharper visual-studio code-snippets

我想知道是否有办法制作#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>
Run Code Online (Sandbox Code Playgroud)

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

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

Gay*_*Fow 12

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

#region MyRegion
//...lots of code...
#endregion // end of MyRegion
Run Code Online (Sandbox Code Playgroud)

您可以使用所谓的"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>
Run Code Online (Sandbox Code Playgroud)

要在Visual Studio中使用它,请将代码段放在.snippet文件中并将其保存在snippets目录中,然后转到Tools => Code Snippets Manager => Add.添加后,您可以使用标准的CTRK K + X来访问它.

唯一能让您通过区域内置片段的内容就是可以灵活地添加尾随注释以指示区域的结束.您还可以通过添加其他扩展来进一步自定义此功能.

注意:sentinal $ end $标记操作完成时光标要着陆的位置.


tod*_*dmo 8

Visual Studio 2017

键入#r TAB TAB,然后键入区域的名称.

这是内置的行为.


ian*_*982 6

按 Control + K、S 并选择区域