views:

82

answers:

2

I am trying to add a code snippet and I want this code to appear in a region. So I tried something like this in the snippet file.

<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>
        rg
        Code Snippet for Region
      </Title>
      <Shortcut>rg</Shortcut>
    </Header>
    <Snippet>
      <References>
        <Reference>
          <Assembly>System.dll</Assembly>
        </Reference>
      </References>
      <Code Language="CSharp">
        <![CDATA[
        #region MyRegion
        // Some Code
        #endregion
        ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

But when I use the code snippet rg, the region appears as expanded by default like this.

 - #region MyRegion
    // Some Code
    #endregion

Is there any way I can get this region as collapsed by default like this?

 + MyRegion
A: 

As far as I know, the insert sippet operation is treated like a normal copy and paste operation. Therefore, I would assume that it is not possible to insert a collapsed region. Especially, as it takes VS some time to recognize it as a region.

Obalix
Quite possible as even some snippets proided by VS appears as expanded. But still I would like to know if it is possible by some means.
Nadeem
+1  A: 
<![CDATA[
#region $RegionName$
$selected$ $end$
#endregion
]]>

You can try this and see if it works.

http://www.mikebevers.be/blog/2009/06/visual-studio-custom-region-code-snippet/

kyndigs
+1 for the useful info. But what I am looking for is that when I use the code snippet it should appear as collapsed.
Nadeem
See the edited question.
Nadeem
Are you saying you just want the region to be collapsed when you use it, I think by default regions are not collapsed, I think in VS2003 if you did #region "region name"Using quotes i think it collapsed the region by default.
kyndigs
@kyndigs: Yes I exactly want that. But typing the region name in "" doesn't serve the purpose for me.
Nadeem
I dont think it is possible then to define a region as collapsed. You could possibly find a way to execute a ctrl+m when you insert the snippet this auto collapses a parent region but its more of a hack than a solution.
kyndigs
I doubt even this can be done. Even if I find some way to get the functionality of Ctrl + M , where am I going to write this? I mean this code should execute every time I insert the code snippet. And I dont think any event gets fired for inserting a code snippet.
Nadeem