How can I stop Resharper from re-ordering my fields & properties only on certain classes?
For the most part, I like how Resharper re-orders my fields & properties. But at other times, I want them to be ordered the way I order them. Is this possible? If so, how?
Please sign in to leave a comment.
supremegrandruler.
If you are asking for a completely ad hoc way to opt out, I know of no way to to so, smarter minds may know bettter. You can, however, apply a consistent, algorithmic ordering pattern using File Layout option. (I spend time in bootstrap/initialization/creation/serialization/IDisposable issues, this pattern reflects that, yours will likely differ) Here is my default which differs from "out of the box" (I in no way claim it is perfect -- it is always a work in progress): I work in C#, StyleCop enforced (it's not perfect), and a few other compliance tools.
And yes, there is a learning curve, but this is the site that gave me what I needed to "roll my own" :)
<?xml version="1.0" encoding="utf-16"?>
<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns">
<TypePattern Priority="100" DisplayName="Type Pattern">
<TypePattern.Match>
<Or>
<And>
<Kind Is="Interface" />
<Or>
<HasAttribute Name="System.Runtime.InteropServices.InterfaceTypeAttribute" />
<HasAttribute Name="System.Runtime.InteropServices.ComImport" />
</Or>
</And>
<HasAttribute Name="System.Runtime.InteropServices.StructLayoutAttribute" />
</Or>
</TypePattern.Match>
</TypePattern>
<TypePattern Priority="100" DisplayName="Type Pattern">
<TypePattern.Match>
<And>
<Kind Is="Class" />
<HasAttribute Name="Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute" Inherited="True" />
</And>
</TypePattern.Match>
<Entry Priority="99" DisplayName="Entry">
<Entry.Match>
<Kind Is="Delegate" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry Priority="98" DisplayName="Entry">
<Entry.Match>
<Or>
<Kind Is="Constant" />
<Kind Is="Field" />
</Or>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Kind Order="Constant" />
<Readonly />
<Static />
<Name />
</Entry.SortBy>
</Entry>
<Entry Priority="97" DisplayName="Entry">
<Entry.Match>
<Kind Is="Enum" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry Priority="96" DisplayName="Entry">
<Entry.Match>
<Kind Is="Constructor" />
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="95" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bClone\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="94" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bDispose\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="93" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bReleaseManagedResources\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="92" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bReleaseUnmanagedResources\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="91" DisplayName="Entry">
<Entry.Match>
<Kind Is="Destructor" />
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="89" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bGetObjectData\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Protected ProtectedInternal Internal Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="88" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="System.Runtime.Serialization.OnSerializingAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="87" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="System.Runtime.Serialization.OnSerializedAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="86" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="System.Runtime.Serialization.OnDeserializingAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="85" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="System.Runtime.Serialization.OnDeserializedAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="79" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="78" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="77" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="76" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="Initialize" />
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry Priority="75" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="Arrange" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="74" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="Act" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="73" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="Teardown" />
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry Priority="72" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="71" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="70" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute" />
</And>
</Entry.Match>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<Static />
<Kind Is="Method" />
<Name Is="Create" />
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<Kind Is="Event" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Property" />
<Not>
<Kind Is="Indexer" />
</Not>
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<Kind Is="Indexer" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Not>
<Kind Is="Destructor" />
</Not>
<Not>
<HandlesEvent />
</Not>
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<HandlesEvent />
<Not>
<Kind Is="Destructor" />
</Not>
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Operator" />
<Not>
<Kind Is="Destructor" />
</Not>
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Abstract />
<Virtual />
<Override />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry" />
<Entry DisplayName="Entry">
<Entry.Match>
<Kind Is="Type" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Name />
</Entry.SortBy>
</Entry>
</TypePattern>
<TypePattern DisplayName="Type Pattern">
<Entry Priority="99" DisplayName="Entry">
<Entry.Match>
<Kind Is="Delegate" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry Priority="98" DisplayName="Entry">
<Entry.Match>
<Or>
<Kind Is="Constant" />
<Kind Is="Field" />
</Or>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Kind Order="Constant" />
<Readonly />
<Static />
<Name />
</Entry.SortBy>
</Entry>
<Entry Priority="97" DisplayName="Entry">
<Entry.Match>
<Kind Is="Enum" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry Priority="96" DisplayName="Entry">
<Entry.Match>
<Kind Is="Constructor" />
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="95" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bClone\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="94" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bDispose\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="93" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bReleaseManagedResources\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="92" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bReleaseUnmanagedResources\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="91" DisplayName="Entry">
<Entry.Match>
<Kind Is="Destructor" />
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="89" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Name Is="\bGetObjectData\b" />
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Protected ProtectedInternal Internal Private" />
</Entry.SortBy>
</Entry>
<Entry Priority="88" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="System.Runtime.Serialization.OnSerializingAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="87" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="System.Runtime.Serialization.OnSerializedAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="86" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="System.Runtime.Serialization.OnDeserializingAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry Priority="85" DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<HasAttribute Name="System.Runtime.Serialization.OnDeserializedAttribute" Inherited="True" />
</And>
</Entry.Match>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<Static />
<Kind Is="Method" />
<Name Is="Create" />
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<Kind Is="Event" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Property" />
<Not>
<Kind Is="Indexer" />
</Not>
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<Kind Is="Indexer" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Method" />
<Not>
<Kind Is="Destructor" />
</Not>
<Not>
<HandlesEvent />
</Not>
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<HandlesEvent />
<Not>
<Kind Is="Destructor" />
</Not>
</And>
</Entry.Match>
<Entry.SortBy>
<Static />
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry">
<Entry.Match>
<And>
<Kind Is="Operator" />
<Not>
<Kind Is="Destructor" />
</Not>
</And>
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Abstract />
<Virtual />
<Override />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Entry" />
<Entry DisplayName="Entry">
<Entry.Match>
<Kind Is="Type" />
</Entry.Match>
<Entry.SortBy>
<Access Order="Public Internal ProtectedInternal Protected Private" />
<Static />
<Name />
</Entry.SortBy>
</Entry>
</TypePattern>
</Patterns>
Thanks that seems very useful but where is the site you mentioned?
I'll have a look at it.
I refined what I need to achieve: basically, any class that has the "Serializable" attribute should not have their fields re-ordered (save static ones).