I am looking for a keyboard short-cut to complete creating the default accessors for a property in a C# class.
Something like...
I start typing:
public int Id
Then I press one or more keys, and I endup with:
public int Id { get; set; }
I am looking for a keyboard short-cut to complete creating the default accessors for a property in a C# class.
Something like...
I start typing:
public int Id
Then I press one or more keys, and I endup with:
public int Id { get; set; }
The shortcut is the trigger "prop":
prop
tabtabint
tabId
tab
and you end up with:
public int Id { get; set; }
Try with propfull
, then TAB Twice and you'll get:
private int myVar;
public int MyProperty
{
get { return myVar;}
set { myVar = value;}
}
You could also create a custom snippet:
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>GetSet</Title>
<Description>Inserts getter/setter shorthand code</Description>
<Shortcut>gs</Shortcut>
</Header>
<Snippet>
<Code Language="CSharp">
<![CDATA[{ get; set; }$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Code Snippet
: msdn.microsoft.com/en-us/library/ms165394.aspx
Sep 24, 2015 at 23:49
gs [tab]
does the whole { get; set; }
Sep 24, 2015 at 23:55
{ get; set; }
and doesn't include a field for the property name, as the other answers do. ...Would've appreciated a citation or pingback; I supposed it's possible you chose completely identical wording independently though.
The shortcut is using CTRL+R and then CTRL+E. Press these keys after writing:
int loginID;
Then you will get the following encapsulation:
int loginID;
public int LoginID
{
get { return loginID; }
set { loginID = value; }
}