Automatically Add Regions to Code in Visual Studio

后端 未结 7 1999
轻奢々
轻奢々 2021-02-20 06:09

My team absolutely loves using regions, and with that in mind it\'s pretty much become a de-facto standard in our code. I recently came to realization that I\'m sick of writing

相关标签:
7条回答
  • 2021-02-20 07:09

    You could create a simple code snippet like the following one:

    <?xml version="1.0" encoding="utf-8"?>
    <CodeSnippets
        xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
      <CodeSnippet Format="1.0.0">
        <Header>
          <Title>Simple</Title>
          <Shortcut>simple</Shortcut>
          <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
          </SnippetTypes>
        </Header>
        <Snippet>
          <Declarations>
            <Literal>
              <ID>name</ID>
              <ToolTip>Replace with the name of the action</ToolTip>
              <Default>Action</Default>
            </Literal>
          </Declarations>
          <Code Language="csharp">
            <![CDATA[
            public void $name$()
            {
                #region ------------- set up -------------
                #endregion 
    
                #region ------------- run test -------------
                #endregion 
            }
            ]]>
          </Code>
        </Snippet>
      </CodeSnippet>
    </CodeSnippets>
    

    Save that file into C:\Users\<your_user>\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets.

    Now you just need to reopen Visual Studio, type 'simple' into a class and press Tab key twice.

    0 讨论(0)
提交回复
热议问题