问题
I've started exporting some of my frequently used blocks of code to custom snippets. Is there a way to get these to show up in IntelliSense and not have to use the snippet browser from the context menu or snippet manager?
At first, I thought this was related to ReSharper, but they still don't show up when I disable the ReSharper IntelliSense.
It would be nice to be able to just use the snippet shortcut instead of using the browser.
回答1:
You need to set the ShortCut
property like <Shortcut>slpropdp</Shortcut>
. The best way to learn editing this, just check any of the already existing codesnippets. By, going to Tools -> Code snippet manager. Select any code snippet, the location of the code snippet will be available at the top location bar
回答2:
If you are still not seeing the shortcut, but you have ReSharper then check in Resharper > Options > IntelliSense > General. If you have ReSharper radio button selected, then your intellisense created in VS [shortcut] will not appear. Change that to Visual Studio or alternatively create intellisense in ReSharper
回答3:
Here is a brief description on how to create your own Snippets in Visual Studio with the 'shortcut' tag.
using a Code Snippet for INotifyPropertyChanged
This is the tag that is required to get the shortcut functionality.
<Shortcut>switch</Shortcut>
Here is a snippet for switch
which is inbuilt into VS
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>switch</Title>
<Shortcut>switch</Shortcut>
<Description>Code snippet for switch statement</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>expression</ID>
<ToolTip>Expression to switch on</ToolTip>
<Default>switch_on</Default>
</Literal>
<Literal Editable="false">
<ID>cases</ID>
<Function>GenerateSwitchCases($expression$)</Function>
<Default>default:</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
switch ($expression$)
{
$cases$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
回答4:
My environment is vs2017 + resharper .After I write a custom .As you can see ,it does not work. here is my solution . There are two options. First , you can use the vs intelligence not the resharper's . Resharper-->Option-->Environment-->IntelliSense-->General , select the "Visual Studio" radio .Second,add a live template or surround template in resharper by the help .
来源:https://stackoverflow.com/questions/3956638/custom-code-snippets-in-intellisense