I've created a code snippet in VS2010. It isn't showing as a shortcut when I start typing. I've called it propnch.
It is available when I use Ctrl-K, Ctrk-X but when I just start typing prop... it isn't showing as an option.
Have I missed some kind of setting somewhere?
I had screen shots, but I don't think SO lets you upload any.
Edit: Screen Shots
I can see my snippet with Ctrl-K, Ctrl-X (its gone grey when I ctrl-PrtScn to take the screenshot)
But It doesn't appear with the other snippet shortcuts.
The snippet code is here (taken from this tutorial) and is in the "Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets" folder.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propnch</Title>
<Shortcut>propnch</Shortcut>
<Description>Code snippet for property and backing field and ensure
that it invokes INotifyPropertyChanigng and INotifyPropertyChanged</Description>
<Author>Abhishek</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
private $type$ $field$;
public $type$ $property$
{
get
{
return $field$;
}
set
{
this.OnPropertyChanging("$property$");
$field$ = value;
this.OnPropertyChanged("$property$");
}
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
It turns out this is a design flaw for the xml editor in VS2010. In the C# editor, you just type the shortcut and press 'tab'. IN the xml editor, it requires two more keystrokes.
To quote from the documentation:
To insert snippets using the shortcut name
1. Position the cursor where you want to insert the XML snippet.
2. Type < in the editor pane.
3. Press ESC to close the IntelliSense complete word list.
4. Type the shortcut name of the snippet, and press TAB to invoke the XML snippet.
According to screenshots, you have ReSharper installed and it overrides VS's IntelliSense behavior. You can either turn off Resharper's overriding or just add right in it a new LiveTemplate. More details here:
http://www.jetbrains.com/resharper/webhelp/Templates__Applying_Templates__Inserting_Imported_Code_Snippets.html
In my case I just added a new ReSharper template:
private $type$ _$loweredProperty$;
public $type$ $property$
{
get { return _$loweredProperty$;}
set
{
if (_$loweredProperty$ == value) return;
_$loweredProperty$ = value;
OnPropertyChanged("$property$");
}
}
adn it works even better: you have to type only two words - type and property name. The backing field will appear with lowered first letter. You must set "$loweredProperty$" to non-editable macros and point it to $property$. That's just a couple of clicks in Template editor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With