Resharper: how to force new private fields at the bottom of the class?

Resharper offers a very useful representation and initialization of the xxx field when you specify a new parameter in the constructor, for example:

Constructor (int parameter)

The only (secondary) annoyance is that it puts a new field at the beginning of the class - and I'm a fan of separating private parts from strangers' prying eyes as far as possible;).

If, however, you already have some private fields in the class, Resharper will place the new field “correctly” (note the quotation marks, I do not want to start a fiery war on this issue) next to them, even if they are at the end of the class.

Is there a way to make Resharper always put new fields at the end of the class?

UPDATE: OK, I forgot to mention that I know about the "Type of members in parameters" function, but any specific help on how to change the template to achieve the placement of the fields will be pleasant.

+3
source share
3 answers

If you have not already done so, you should report an error on the ReSharper Jira website:

http://www.jetbrains.net/jira/browse/RSRP

Look first, someone has already reported this. If so, you can vote on their problem and receive notifications of any changes in it.

0
source

In the "Create Element Wizard" you can find and move the next XML block

<!--fields and constants-->
<Entry>
  <Match>
    <Or>
      <Kind Is="constant"/>
      <Kind Is="field"/>
    </Or>
  </Match>
  <Sort>
    <Kind Order="constant field"/>
    <Static/>
    <Readonly/>
    <Name/>
  </Sort>
</Entry>

The bottom of the template is the default. Basically two lines form the bottom of the file

    <!--HERE-->

  </Pattern>      
</Patterns>

, , , , . ( , " " )


, , , :

<Match>
  <And>
    <Access Is="private"/>
    <Or>
      <Kind Is="constant"/>
      <Kind Is="field"/>
    </Or>
  </And>
</Match>

, "" "" , , - , . .

+4

" " Resharper.

In the "Default Template" section of the XML layout definition, simply move the input element that groups your fields at the end of the section, after methods, events, properties, etc.

0
source

Source: https://habr.com/ru/post/1708269/


All Articles