Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper 6 create auto property by default

Tags:

c#

resharper

When I write code and need new property, i simply write propery name as it would exist already and choose action from menu: create new property in resharper

Problem is, that it generates code like this:

 protected int SomeNewProperty
    {
        get { throw new System.NotImplementedException(); }
        set { throw new System.NotImplementedException(); }
    }

So I need to go there and manually adjust that (actually I prefer to choose Create field from menu and change it to auto property). Anyway, I thought, may be there is a way to change default behavior of "Create property", that it would create auto property instantly?

Update

In Resharper 8 auto properties are available and may be set by default!

Resharper 8 Option Screen

like image 215
Giedrius Avatar asked Sep 28 '11 13:09

Giedrius


4 Answers

You cannot do this in R# (at least in v6). That is, create a pseudo property and have resharper generate the Auto Property stub.

You can still use the superior method that Visual Studio uses. Type out your new property which will show as a syntax error and then CTRL + . shows VS mini menu. Then just hit enter and straight away, the job is done.

It does not take you to the class file which can be distracting too. To use the shortcut above, you don't even need to have you cursor on the broken property name.

So this is better than the method described by Rickard as it is faster and less distracting you away from the code you are writing.

like image 55
Valamas Avatar answered Nov 07 '22 18:11

Valamas


Just when you click Create property it will halt on the type. Hit tab and you will get a context menu with the option to use Auto property.

enter image description here

like image 43
Rickard Avatar answered Nov 07 '22 16:11

Rickard


There is an option to change default body style.

However, the close you can get is

    protected int SomeProperty
    {
        get { return 0; }
        set { }
    }

Resharper Options

like image 7
Jerry Liang Avatar answered Nov 07 '22 16:11

Jerry Liang


There is a default snippet that comes with Visual Studio called 'prop' Just type that, hit , give a type name and give it a name. Done and done.

I know that doesn't answer your question in terms of Resharper, but it is functionality already provided by the Visual Studio IDE.

like image 1
A.R. Avatar answered Nov 07 '22 18:11

A.R.