tags:

views:

341

answers:

3

novice question but here it goes.

I type prop then tab in VS 2008 (or whatever VS). I'm using Resharper.

I tab, give it a type, tab again and have to delete the text for the property name before I can start typing it. Ok fine.

Now here is the question, at this point I'm left with this:

public string Maxlength { get; set; }

is there a quick way to get it like this so that I can start filling in my get and set?

public string Maxlength { get{;} set{;} }

for some reason, I'm not good yet with stubbing out props quick. Just have to get the hang of the shortcut or whatever as well as with Resharper.

+1  A: 

In Visual Studio 2008 the prop snippets have been changed to output automatically implemented properties. To use the older snippet which expands the get and set blocks you will need to create a new snippet to do so.

Here is one I created that is a bit more flexible than the default one that Visual Studio gives you:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;
    <CodeSnippet Format="1.0.0">
     <Header>
      <Title>propfull</Title>
      <Shortcut>propfull</Shortcut>
      <Description>Code snippet for creating a property</Description>
      <Author>Andrew Hare</Author>
      <SnippetTypes>
       <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
     </Header>
     <Snippet>
      <Declarations>
       <Literal>
        <ID>type</ID>
        <Default>String</Default>
        <ToolTip>property type</ToolTip>
       </Literal>
       <Literal>
        <ID>fname</ID>
        <Default>name</Default>
        <ToolTip>field name</ToolTip>
       </Literal>
       <Literal>
        <ID>pname</ID>
        <Default>Name</Default>
        <ToolTip>property name</ToolTip>
       </Literal>
       <Literal>
        <ID>access</ID>
        <Default>public</Default>
        <ToolTip>property visibility</ToolTip>
       </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[$type$ $fname$;

      $access$ $type$ $pname$
      {
       get { return this.$fname$; }
       set { this.$fname$ = value; }
      }$end$]]>
      </Code>
     </Snippet>
    </CodeSnippet>
</CodeSnippets>
Andrew Hare
A: 

When you want to "fill" an autoproperty go onto the variable name and press Alt+Ins and select "To property with backing fields" - it will result in:

private string m_Maxlength;
public string Maxlength
{
  get { return m_Maxlength; }
  set { m_Maxlength = value; }
}

Or you can change the live template (ReShaper -> Live Templates -> Predefined Templates -> C# -> prop" - then edit:

public $TYPE$ $NAME$ { get {$END$;} set{;} }
tanascius
Nice, I just went in there and edited to change it to the format I like. Now doing "prop" expands out like I want automatically:public $TYPE$ $NAME${ get{;} set{;}}
CoffeeAddict
Have a look at my answer - which suggests to use the $END$ keyword - this marks the last cursor position. So you can even save some more keystrokes.
tanascius
A: 

ReSharper might be taking over that property snippet. You might want to look at the ReSharper | Live Templates... menu.

Mark

related questions