Skip to main content

Organize Members

  • 5 minutes to read

The Organize Members feature allows you to organize type members according to specified rules. This helps you maintain a unified type structure and locate members.

Configure Organize Members

Access Configuration Settings

Open the Editor | All Languages | Organize Members options page.


Refer to the following topic for information about Organize Members configuration options: Organize Members Settings.

Choose a Predefined Rule Set

CodeRush has two predefined rule sets: Default and StyleCop. These sets can be helpful if you work on projects with different standards.


You can configure rules based on the predefined rule sets or create new rule sets.

Create a Rule Set (Optional)

To create an empty rule set, perform the following actions:

1) Click New in the “Rule set” section.


2) In the invoked dialog, you can change the suggested rule set name (for example, to “My Rule Set”) or leave it as is. Click OK to save the rule set name and close this dialog.


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


To create a rule set based on the existing rule set:

1) Choose a rule set which rules CodeRush must clone and click Clone.


2) In the invoked dialog, you can change the suggested rule set name or leave it as is. Click OK to save the rule set name and close this dialog.


The screenshot below shows the rule set cloned from “StyleCop”.


Add Rules to a Rule Set and Customize Them

You can add rules to any rule set. Refer to the following example for information on how to add a rule to the “Default” rule set: How to: Create a Rule.

To add rules to a new rule set, follow the steps below:

1) Choose an empty rule set.

2) Click Add Rule.


CodeRush creates a new rule and shows its settings.


3) Change the suggested “New rule” name, for example, to “Constants” and press Enter to save it.


4) Change the Rule priority (optional). Possible values: High priority, Normal priority, and Low priority.


Use this setting to group members with different kinds prior to other rules, for example, explicit interface implementations. For more information, see the following example: How to: Create Regions for Explicit Interface Implementations

5) In the Group by section, click the drop-down menu and set the Node kind to Constant.


6) Specify how many empty lines CodeRush should add between members in the Empty line count between members text box (optional). The default value is 0.


7) Leave the Sort by settings as is for the “Constants” rule to sort constants by name.

CodeRush can also sort members by kind, access modifier, visibility, and other criteria. You can specify ascending or descending sort order.

The screenshot below shows the specified “Constants” rule settings:


8) Click Add Rule to add a rule for “Fields”.

9) Change the suggested rule name to “Fields” and press Enter.


CodeRush can duplicate any rule in the rule set. Select a rule (for example, the “Constants” rule) and click the Duplicate button.
CodeRush adds the copied rule to the end of the rule list.


10) In the “Group by” section, set Node kind to Field.

11) In the “Sort by” section: set the Sort by to Static and click Add to add the second “Sort by” criteria.


Set the Sort by combo box to Name.


This allows CodeRush to sort fields by static modifier and by name in ascending order.

The following screenshot shows the specified “Fields” rule settings:


12) Add a new rule.

13) Change the suggested rule name to “Methods” and press Enter.

14) In the “Group by” section, set Node kind to Method.

The screenshot below shows the specified “Methods” rule.


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

Run Organize Members

1) Place the caret in a class member in the code snippet below:

namespace Example
    public class MyClass
        private static int field3;
        private int field1;
        private static string field4;
        private const string const2 = "My Model";
        private const int const1 = 140;

        private void Method2 () {}
        private int field2;
        private void Method1() { }

2) Press Ctrl +. or Ctrl + ~ to invoke the Code Actions Menu.

3) Choose Organize Members from the menu and press Enter.

CodeRush places members into groups and applies members rules according to the specified order (Constants, Fields, and Methods).



You can also run the Organize Members feature in Code Cleanup.

See Also