File clean up removed my existing regions

Hey. I have a file pattern that would re-arrange my code into a certain format. However, I do not want it to remove my existing #regions. so I set [Remove Regions] to None. However, it doesn't work. I have attached the pictures here. Hope I can get some answers here.

 

Below is my file pattern:

<?xml version="1.0" encoding="utf-16"?>
<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns">
  <FilePattern>
    <Entry DisplayName="Externs">
      <Entry.Match>
        <Extern />
      </Entry.Match>
    </Entry>
    <Entry DisplayName="Namespaces">
      <Entry.Match>
        <Kind Is="Namespace" />
      </Entry.Match>
    </Entry>
    <Entry DisplayName="Delegates">
      <Entry.Match>
        <Kind Is="Delegate" />
      </Entry.Match>
    </Entry>
    <Entry DisplayName="Enums">
      <Entry.Match>
        <Kind Is="Enum" />
      </Entry.Match>
    </Entry>
    <Entry DisplayName="Interfaces">
      <Entry.Match>
        <Kind Is="Interface" />
      </Entry.Match>
    </Entry>
    <Entry DisplayName="Structs">
      <Entry.Match>
        <Kind Is="Struct" />
      </Entry.Match>
    </Entry>
    <Entry DisplayName="Classes">
      <Entry.Match>
        <Kind Is="Class" />
      </Entry.Match>
    </Entry>
    <Entry DisplayName="All Other Members" />
  </FilePattern>
  <TypePattern DisplayName="StyleCop SA1201 Class Pattern" Priority="0">
    <Region Name="Constants">
      <Entry DisplayName="Constants">
        <Entry.Match>
          <Kind Is="Constant" />
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Static Fields">
      <Entry DisplayName="Static Fields">
        <Entry.Match>
          <And>
            <Kind Is="Field" />
            <Static />
          </And>
        </Entry.Match>
        <Entry.SortBy>
          <Readonly />
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Fields">
      <Entry DisplayName="Fields">
        <Entry.Match>
          <And>
            <Kind Is="Field" />
            <Not>
              <Static />
            </Not>
          </And>
        </Entry.Match>
        <Entry.SortBy>
          <Readonly />
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Dependency Property">
      <DependencyProperty DisplayName="Dependency Properties" Priority="100">
        <Entry DisplayName="DP Key">
          <Entry.Match>
            <DependencyPropertyPart Match="Key" />
          </Entry.Match>
        </Entry>
        <Entry DisplayName="DP Field">
          <Entry.Match>
            <DependencyPropertyPart />
          </Entry.Match>
        </Entry>
        <Entry DisplayName="DP Handler">
          <Entry.Match>
            <DependencyPropertyPart Match="Handler" />
          </Entry.Match>
        </Entry>
        <Entry DisplayName="DP Property">
          <Entry.Match>
            <DependencyPropertyPart Match="Property" />
          </Entry.Match>
        </Entry>
        <Entry DisplayName="Attached DP Getter">
          <Entry.Match>
            <DependencyPropertyPart Match="Getter" />
          </Entry.Match>
        </Entry>
        <Entry DisplayName="Attached DP Setter">
          <Entry.Match>
            <DependencyPropertyPart Match="Setter" />
          </Entry.Match>
        </Entry>
      </DependencyProperty>
    </Region>
    <Region Name="Constructors">
      <Entry DisplayName="Constructors">
        <Entry.Match>
          <Kind Is="Constructor" />
        </Entry.Match>
        <Entry.SortBy>
          <Static />
          <Access />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Destructors">
      <Entry DisplayName="Destructors">
        <Entry.Match>
          <Kind Is="Destructor" />
        </Entry.Match>
        <Entry.SortBy>
          <Static />
          <Access />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Delegates">
      <Entry DisplayName="Delegates">
        <Entry.Match>
          <And>
            <Kind Is="Delegate" />
          </And>
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Events">
      <Entry DisplayName="Events">
        <Entry.Match>
          <Kind Is="Event" />
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Enum: ${0}" Priority="100">
      <Region.GroupBy>
        <Name />
      </Region.GroupBy>
      <Entry DisplayName="Enums">
        <Entry.Match>
          <And>
            <Kind Is="Enum" />
          </And>
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Interface: ${0}" Priority="100">
      <Region.GroupBy>
        <ImplementsInterface Immediate="True" />
      </Region.GroupBy>
      <Region Name=" Static Fields">
        <Entry DisplayName="Interface Static Fields">
          <Entry.Match>
            <And>
              <Kind Is="Field" />
              <Static />
              <ImplementsInterface Immediate="True" />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Readonly />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region Name="Fields">
        <Entry DisplayName="Interface Fields">
          <Entry.Match>
            <And>
              <Kind Is="Field" />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Readonly />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region Name="Delegates">
        <Entry DisplayName="Interface Delegates">
          <Entry.Match>
            <And>
              <Kind Is="Delegate" />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region Name="Events">
        <Entry DisplayName="Interface Events">
          <Entry.Match>
            <And>
              <Kind Is="Event" />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region>
        <Entry DisplayName="Static Interface Properties">
          <Entry.Match>
            <And>
              <Kind Is="Property" />
              <Static />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region Name="Properties">
        <Entry DisplayName="Interface Properties">
          <Entry.Match>
            <And>
              <Kind Is="Property" />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region Name="Indexers">
        <Entry DisplayName="Interface Indexers">
          <Entry.Match>
            <And>
              <Kind Is="Indexer" />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region Name="Static Methods">
        <Entry DisplayName="Interface Static Methods">
          <Entry.Match>
            <And>
              <Kind Is="Method" />
              <Static />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region Name="Methods">
        <Entry DisplayName="Interface Methods">
          <Entry.Match>
            <And>
              <Kind Is="Method" />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
      <Region Name="All Other Members">
        <Entry DisplayName="All Other Interface Members">
          <Entry.Match>
            <And>
              <Kind Is="Member" />
              <ImplementsInterface />
            </And>
          </Entry.Match>
          <Entry.SortBy>
            <ImplementsInterface />
            <Kind Is="Member" />
            <Access />
            <Name />
          </Entry.SortBy>
        </Entry>
      </Region>
    </Region>
    <Region Name="Static Properties">
      <Entry DisplayName="Static Properties">
        <Entry.Match>
          <And>
            <Kind Is="Property" />
            <Static />
          </And>
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Properties">
      <Entry DisplayName="Properties">
        <Entry.Match>
          <Kind Is="Property" />
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Indexers">
      <Entry DisplayName="Indexers">
        <Entry.Match>
          <Kind Is="Indexer" />
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Static Methods">
      <Entry DisplayName="Static Methods">
        <Entry.Match>
          <And>
            <Kind Is="Method" />
            <Static />
          </And>
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Methods">
      <Entry DisplayName="Methods">
        <Entry.Match>
          <Kind Is="Method" />
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="All Other Members">
      <Entry DisplayName="All Other Members">
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
    <Region Name="Nested type: ${0}">
      <Region.GroupBy>
        <Name />
      </Region.GroupBy>
      <Entry DisplayName="Nested Structs">
        <Entry.Match>
          <Kind Is="Struct" />
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
      <Entry DisplayName="Nested Classes">
        <Entry.Match>
          <Kind Is="Class" />
        </Entry.Match>
        <Entry.SortBy>
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
      <Entry DisplayName="All Other Nested Types">
        <Entry.Match>
          <Kind Is="Type" />
        </Entry.Match>
        <Entry.SortBy>
          <Kind Is="Member" />
          <Access />
          <Name />
        </Entry.SortBy>
      </Entry>
    </Region>
  </TypePattern>
</Patterns>

0
5 comments
Hello Gary,

thank you for contacting us.
I couldn't reproduce the issue from scratch.
Could you please provide some code example for which regions are removed?
Please also provide all dotSettings files via ``ReSharper | Manage Options | right-click on each layer | Export to file``.
Thank you.
0

Thanks for the reply. I have attached my Resharper settings on my onedrive.

https://1drv.ms/u/s!Ahd_lIAtyq8Ns6RFhHu51yTOI6WEow?e=vaibhD 

Any code would work the same way. Here is a short example. 

Assuming I have a class like below, it contains one #region which coded by myself.

public class BayBuilderUnitTest
    {
        public static readonly string _testStaticField = "Sample";

        private string _testField1;

        #region My own region
        private double _testField2;
        #endregion

        public void BuildDoubleDeepBay()
        {
            Console.WriteLine($@"Just a test.");
      }
    }

 

 

After press Ctrl + F to use [Resharper - Code Cleanup --- Full Cleanup], which would apply my file layout. However, it would removed my own region and creates the #region based on the file layout I created previously.

    public class BayBuilderUnitTest
    {
        #region Static Fields

        public static readonly string _testStaticField = "Sample";

        #endregion

        #region Fields

        private string _testField1;
        private double _testField2;

        #endregion

        #region Methods

        public void BuildDoubleDeepBay() { Console.WriteLine(@"Just a test."); }

        #endregion
    }
0
Hello Gary,

thank you for the provided info.
Could you please also specify what should be the expected result for the specified code sample? Currently, it's not quite evident how ReSharper should generate regions and keep regions for the same class members.
Thank you.
0

Hey Angeline,

What I am expecting is that the Resharper keeps my #region when it finished reformat. Below is my expecting result. 

So first, assuming I have the below code which I use `#region My Region` to wrap the `_testField2`

public class BayBuilderUnitTest
    {
        public static readonly string _testStaticField = "Sample";

        private string _testField1;

        #region My own region
        private double _testField2;
        #endregion

        public void BuildDoubleDeepBay()
        {
            Console.WriteLine($@"Just a test.");
      }
    }

 

Then, Resharper reformats my code but still keeps my `#region My Region`. Below is the expecting result. However, the reality is that ReSharper would remove my `#region My Region`.

 

public class BayBuilderUnitTest
    {
        #region Static Fields

        public static readonly string _testStaticField = "Sample";

        #endregion

        #region Fields

        private string _testField1;

#region My Region
        private double _testField2;
#endregion

        #endregion

        #region Methods

        public void BuildDoubleDeepBay() { Console.WriteLine(@"Just a test."); }

        #endregion
    }
0
Hello,

thank you for the clarification.
I've filed a corresponding issue - https://youtrack.jetbrains.com/issue/RSRP-490850/File-layout-should-keep-existing-regions-while-adding-new-ones-for-the-same-entities. Please feel free to comment or vote for it.
Let me know if you have any more questions.
Thank you.
0

Please sign in to leave a comment.