4

Resharper provides a feature to create and initialize an autoproperty from a constructor parameter.

By default, the generated property is of the form:

public int Foo { get; set; }

Is it possible to modify the accessors to have this instead?

protected int Foo { get; private set; }
  • I don't think so. There are quire a few things you can set in Resharper, but as far as I can tell the property generation is not linkable to a template. – jessehouwing Oct 08 '14 at 07:43

2 Answers2

2

I checked with JetBrains and this is what they said:

Hi Jesse, No, it is not possible in the currently. You are welcome, however, to log a feature request in our issue tracker

So the answer is: No.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Should you log a feature request, post the link here :). – jessehouwing Oct 08 '14 at 13:11
  • 1
    Thanks for your answer! I filed a [request](http://resharper-support.jetbrains.com/requests/11670) to JetBrains – Olivier Blanc Oct 10 '14 at 08:05
  • @OlivierBlanc FYI the resource you mentioned before leads to a 404. There is one similar issue out there I could find @ [RSRP-458465 Generate readonly properties](https://youtrack.jetbrains.com/issue/RSRP-458465#u=1461653836660). – Peter Majeed Jul 07 '16 at 12:03
1

To generate this property I guess you are using the prop template

So you can either change it, or create a new one of your own

Go to ReSharper Menu -> Templates Explorer

Choose C# and look for prop , you can click edit and change it

But maybe the best way is to create a new one if you sometimes want default properties

Click new template and write that

protected $TYPE$ $NAME$ { get; private set; }

In the shortcut field type what you want, like prprop for example and save it.

Now open a file and type prprod, tab twice and you got the protected propertiy with private setter

If you are not using templates or snippets but the "Create auto-property from constructor" it seems it's impossible to change the access modifier, the only way to change it is when you use

Resharper -> Edit -> Generate Code ...

Then from there what you choose to generate you can change access modifiers or choose if it's read only.

Aurelien Souchet
  • 721
  • 5
  • 11
  • 2
    Sorry, i wasn't precise enough. I was talking about the generated properties from a constructor parameter, I modified the question accordingly – Olivier Blanc Oct 08 '14 at 08:06