I've been trying to get ReSharpers Code Cleanup to not only sort any members alphabetically by name, but to sort them primarily by their type (whether that be a methods return type or a properties type etc.), then by their name.
For example:
#region " Properties "
public string Name { get; set; }
public int Age { get; set; }
#endregion
#region " Instance Methods "
public void SecondMethod()...
public void FirstMethod()...
public Post GetPost()...
public List<Post> GetPosts()...
#endregion
Would become:
#region " Properties "
public int Age { get; set; }
public string Name { get; set; }
#endregion
#region " Instance Methods "
public List<Post> GetPosts()...
public Post GetPost()...
public void FirstMethod()...
public void SecondMethod()...
#endregion
Ideally, I would like the other default behaviours to remain the same e.g. where Constructors, Properties are positioned/grouped, and if a number of members appear within a region (as in the example above), for that group of members to be sorted independently from members outside of that group/region.
Can anyone recommend the code necessary within the ReSharper Type Members Layout pattern editor to achieve this please?
Looking at the Type Member Layout in Resharper, I'm guessing this isn't possible. Here's a sample snippet for the events region:
<Entry>
<Match>
<Kind Is="event"/>
</Match>
<Sort>
<Access Order="public internal protected-internal protected private" />
<Static />
<Name/>
</Sort>
<Group Region="Events"/>
</Entry>
Here's an article from JetBrains themselves: In-depth look at customizing type layout with resharper.
It looks like there is no qualifier for return type for sorting unfortunately. Here are the options, referenced in that post:
- <Kind Is=”$val” [Order=”$val”]>
- <Name Is="$val” [IgnoreCase=”true/false”]>
- <HasAttribute CLRName=”$val” [Inherit=”true/false”]>
- <Access Is=”$val”>
- <Static/>
- <Abstract/>
- <Virtual/>
- <Sealed/>
- <Readonly/>
- <ImplementsInterface CLRName=”$val” [Immediate=”true/false”]>
- <HandlesEvent/>
You could contact JetBrains and request that a new operand be added to the list. Seems fairly simple. Could be something like:
<ReturnType="$val" [Order="$val"][AlphaOrder="true/false"]>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With