Visual Studio: macro for creating custom comments (code snippet)

I would like to generate such a formatted chapter comment with a label

//##########################################################
//                    METHOD-NAME-HERE
//##########################################################
public static IShouldBeSleepingAtThisTime(DateTime veryLate)
{        
   ForceStopCoding();
   CallGFToApologize(veryLate);
   GoBackHome();  
}

Ideally, I would like to override / customize the behavior of the generated codes with three slashes in the "#" lines and other information, as this improves the readability of the code for large classes.

EDIT:
In addition to TheChrisKent, a very useful snippet, found a quick little Tuto Agafonov Vyacheslav on how easy it is to integrate it into VS HERE

+3
source share
3 answers

Create an XML file with the extension .snippet and place it inside:

<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>OglethorpeComments</Title>
    <Author>Mika Jacobi</Author>
    <Shortcut>ogle</Shortcut>
    <Description>pretty comments with #</Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Declarations>
      <Literal>
        <ID>Method</ID>
        <Default>Method-Name-Here</Default>
      </Literal>
    </Declarations>
    <Code Language="CSharp">
      <![CDATA[//##########################################################
//                    $Method$
//##########################################################]]>
    </Code>
  </Snippet>
</CodeSnippet>

: http://www.visualstudiotutor.com/2010/02/create-snippet-visual-studio-2010/

+7

,

0

Thought I would share what I did. I created a fragment, in the header section I added a shortcut to the shortcuts.

<Shortcut>---</Shortcut>

Now I can enter β€œ---” and click on the tab, and a comment fragment will appear.

0
source

Source: https://habr.com/ru/post/1791490/


All Articles