开发者

VS2010 Code Snippet Shortcut Not Showing

开发者 https://www.devze.com 2023-02-28 04:20 出处:网络
I\'ve created a code snippet in VS2010. It isn\'t showing as a shortcut when I start typing. I\'ve called it propnch.

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 ta开发者_运维百科ke the screenshot)

VS2010 Code Snippet Shortcut Not Showing

But It doesn't appear with the other snippet shortcuts.

VS2010 Code Snippet Shortcut Not Showing

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.


Too a sec to realize, but it's simple: you were missing the </CodeSnippets> at the end.


CTRL +K+ X

or Right click on code page will show you the snippet

right click and start intellisense in Visualstudio


Go in Extensions and Updates of Visual Studio and then click on Online Tab and then in search type Bootstrap.

Install following Packs to enable intellisense

  1. Bootstrap Bundle
  2. Bootstrap Snippet Pack


If it is snippets for XML language it must be placed in next directory

C:\Users\%user%\Documents\Visual Studio 2015\Code Snippets\XML\My Xml Snippets\

For adding one of them to your document you must call snippet context menu by ctrl+K, ctrl+X. Your snippets will be in "My Xml Snippets"


This may come a little bit late but if you are debugging a program CTRL K + CTRL X will not work. Stop debugging your program and try it again. it worked for me in VS 2013 and without Resharper.

0

精彩评论

暂无评论...
验证码 换一张
取 消