Create 'prop' or 'propfull' shortcut in Visual Studio

5

I would like to create within Visual Studio a shortcut of type prop or propfull so that it automatically creates a snippet of code.

TAB

public int MyProperty { get; set; }
TAB

private int myVar;

public int MyProperty
{
    get { return myVar; }
    set { myVar = value; }
}

I wanted to create a shortcut for it to create a snippet of code that I need to repeat several times, does anyone know if this is possible?

    
asked by anonymous 18.05.2018 / 18:06

2 answers

6

Yes, it is possible, this is called snippet . The resource documentation is here .

Go to the Tools menu - > Code Snippets Manager and import the * snippet that you created. The file that contains your definition follows this template:

<?xml version="1.0" encoding="utf-8"?>  
<CodeSnippets  
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">  
    <CodeSnippet Format="1.0.0">  
        <Header>  
            <Title></Title>  
        </Header>  
        <Snippet>  
            <Code Language="">  
                <![CDATA[]]>  
            </Code>  
        </Snippet>  
    </CodeSnippet>  
</CodeSnippets>

In CDATA goes the code you want to be expanded when you enter the chosen keyword ( <Shortcut>hello</Shortcut> ). You can create "variables" in the template ( $SqlConnString$ ):

<Declarations>  
    <Literal>  
        <ID>SqlConnString</ID>  
        <ToolTip>Replace with a SQL connection string.</ToolTip>  
        <Default>"SQL connection string"</Default>  
    </Literal>  
    <Object>  
        <ID>SqlConnection</ID>  
        <Type>System.Data.SqlClient.SqlConnection</Type>  
        <ToolTip>Replace with a connection object in your application.</ToolTip>  
        <Default>dcConnection</Default>  
    </Object>  
</Declarations>

You have a plugin that helps . You have one from Microsoft . It had the SnippetEditor , but was abandoned. You also have other best commercials .

But it compares to the available in Resharper . It's another life.

First make sure you do not have it ready. There are several collections of snippets ready.

    
18.05.2018 / 18:27
3

Yes, this is called a snippet, or in English Snippet , install an Snippet Desinger (completely free) according to the figure below accessed by the menu: Tools -> Extensions and Updates :

  

andlookforthe Snippet Desinger :

  

AfterinstallingandrestartingyourVisualStudioitissimpletocreateSnippettouseinyourprojectsintheFile->New->File:

  

searchforCodeSnippet:

  

willopenascreenwiththefollowingcharacteristics:

  

followingtheupperconfiguration:

  • Snippet:NameofSnippetcreated
  • Language:Chooselanguage
  • Shortcut:Excerptname,nickname
  • Inthegraypartofthecodeyouwanttocreatefromthisshortcutwhereitcanevencontaintypingparameterswhicharetextsthatarebetween$.

InthiscaseaSnippetwascreated,forSqlConnectionasanexample:typedsqlconandpressingTABandintheconnectionparameterparttotype,note:

  

withtwoTABiscreated:

References:

18.05.2018 / 18:32