All docs
V20.2
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

How to: Wrap Multiple Sections into Regions

  • 3 minutes to read

CodeRush can wrap each member section into a region and surround these member sections with the parent region.

namespace MyApp
{
    public class Example
    {
        #region Private fields, private events, and private methods 
        #region Private fields
        object field1;
        object field2;
        #endregion
        #region Private events
        event EventHandler EventName1;
        event EventHandler EventName2;
        #endregion
        #region Private methods
        void MethodName1() { }
        void MethodName2() { }
        #endregion
        #endregion
    }
}

Follow the steps below to achieve the result shown in the code snippet above:

  1. Open the Editor | All Languages | Organize Members options page to configure the Organize Members feature.

  2. In the "Rule set" section, click New to open the "New Set" dialog.

  3. Rename the suggested rule set name, for example, to "My Rule Set". Click OK to save the rule set name and close the "New Set" dialog.

    CodeRush creates an empty rule set that you can populate with member rules.

  4. Click Add Rule to create a new rule.

    CodeRush adds the new rule to the rule set.

  5. Change the suggested rule name to "Private fields" and press Enter to save this change.

  6. In the "Group by" section, specify the following condition for the "Private fields" rule:

    For more information on how to configure grouping, see the following example: How to: Create a Rule

  7. Add a rule (see the step 4), name it "Private events", and specify the following grouping condition:

  8. Add a rule for private methods with the following grouping condition:

  9. Select the "Private fields" rule and click Region to wrap this rule into a region.

  10. Press Enter to apply the suggested region name for private fields.

    CodeRush shows the "Member section name" field set to "Fields" in the right part of the options page.

    NOTE

    CodeRush can wrap fields, methods, or properties into a region when you expand a template. For more information, see the following topic: Member Sections.

  11. Repeat steps 9-10 to wrap "Private events" and "Private methods" rules into a region.

  12. Select the "Region: Private methods" item and click Region.

  13. Change the suggested region name to: "Private fields, private events, and private methods".

  14. Use drag & drop to position "Region: Private events" and "Region: private fields" items inside "Region: Private fields, private events, and private methods", as shown in the screencast below:

  15. Click Apply and OK to save the changes, and close the Organize Members options page.

  16. Place the caret in a class member in the code snippet below:

    using System;
    
    namespace MyApp
    {
        public class Example
        {       
            object field1;
            event EventHandler EventName1;
            void MethodName1() { }
            object field2;        
            event EventHandler EventName2;      
            void MethodName2() { }        
        }
    }
    
  17. Press Ctrl+. or Ctrl+~ to invoke the Code Actions menu.

  18. Choose Organize Members from the menu and press Enter.

CodeRush groups private fields, private events, and private methods according to the specified rule order and wraps these members into regions.