I have seen some people creating properties in C# really fast, but how did they do it?
What shortcuts are available in Visual Studio (currently using Visual Stu
Go to
Tools >> Options >> Text Editor >> C# >> IntelliSense
Under the Snippets behaviour section:
Make sure "Always include snippets" is selected.
I hope it works for you too.
When you write in Visual Studio,
public ServiceTypesEnum Type { get; set; }
public string TypeString { get { return this.Type.ToString();}}
ReSharper will keep suggesting to convert it to:
public string TypeString => Type.ToString();
In visual studio 2017 community, the key is ctrl + .
ReSharper offers property generation in its extensive feature set. (It's not cheap though, unless you're working on an open-source project.)
I think Alt+R+F is the correct one for creating property from a variable declaration
In addition to Amra's answer, you can find other snippets by typing
Ctrl + K, Ctrl + X
Which is mapped to Edit.InsertSnippet in my Visual Studio and shows you the full list of snippets available.
Also remember that you can configure your own snippets by using the Snippets Manager, which is available in the Tools
menu, Code Snippets Manager...
.
Basically you create a file *.snippet
and use the Import button in the Code Snippets Manager to add it to Visual Studio.
For a full tutorial you can go to the docs; Walkthrough: Create a code snippet.
In Visual Studio Code snippets are handled slightly different than in Visual Studio. You can access all snippets by typing Ctrl + Shift + P and type in snippet
. Two options should be available, Insert Snippet
and Preferences: Configure User Snippets
.
The former inserts a snippet from your list of snippets (using the Language Mode which you can see in the status bar), and with the latter you can create your own snippets for any Language Mode.
If you know the shortname you can just type that and use Tab to expand the snippet. For inserting a C# property you have three snippets available, prop
, propfull
, and propg
, for different purposes.