Resharper 9 File Layout: defining sort order when sorting by access modifier not possible?

北城以北 提交于 2019-12-10 14:56:12

问题


after installing R# 9.0 my custom file layout from 8.2 did not work anymore. I recreated the same pattern using the layout designer which is new in 9.0.

The part I could not reproduce was the detailed ordering definition for properties using access modifiers:

Pre-9.0 it looked like this:

[...]
<Sort>
    <Access Order="private public internal protected-internal protected"/>
</Sort>
[...]

... resulting in the properties being ordered as defined - especially: private first!

In 9.0 when using the new Designer the produced XAML is the following:

[...]
<Entry.SortBy>
    <Access />
</Entry.SortBy>
[...]

... which still sorts the members by their access modifier but using some default ordering spec. The designer does not allow for specifying any additional attributes and editing the XAML manually as in pre-9.0 produces errors.

Is there any way in R# 9.0 to control the order of public, private etc members like this?

Btw. the same issue exists for other sort specs like Kind: it is not possible anymore to specify that e.g. property should go before method etc.


回答1:


As it turns out the ordering can still be specified as in pre-9.0 - but with slightly different syntax:

[...]
<Entry.SortBy>
    <Access Order="private public internal protectedinternal protected"/>
</Entry.SortBy>
[...]

The difference was that protected-internal now has to be protectedinternal instead...

Also be aware that you have to do this manually in the XAML view since the visual layout designer does not support this setting yet. (But it will detect errors in your edits - so be sure to switch back and forth from XAML to Designer view to check if you broke anything).

For the second part regarding kinds: they can be sorted, too. This was a oversight of mine.

Edit: A whole entry then looks like this:

<Entry DisplayName="non-private Fields">
  <Entry.Match>
    <And>
      <Kind Is="Field" />
      <Not>
        <Access Is="Private" />
      </Not>
    </And>
  </Entry.Match>
  <Entry.SortBy>
    <Access Order="Public Internal ProtectedInternal Protected Private" />
    <Name Is="Enter Pattern Here" />
  </Entry.SortBy>
</Entry>


来源:https://stackoverflow.com/questions/27802756/resharper-9-file-layout-defining-sort-order-when-sorting-by-access-modifier-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!