All docs
V21.1
21.1
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: Create a Rule

  • 2 minutes to read

Follow the steps below to create a new rule for private enumerators:

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

    organize-members-page

  • Click Add Rule to create a new rule.

    add-rule-button

    CodeRush adds the new rule to the end of the rule list.

  • Change the suggested rule name to “Private enumerators” and press Enter to save the change.

    rule-name

  • Change the “Private enumerators” rule’s position, as shown in the screencast below, so that private enumerators follow events in a type. To change the rule’s position, drag the “Private enumerators” rule in the rule list and drop it when you reach the desired position.

    change-rule-position-for-enums

    When you run Organize Members, CodeRush changes the type’s member order to correspond to the order of the rules in the rule set.

  • Configure grouping:

    • Select the “Private enumerators” rule.

    • In the “Group by” section, click the “+” button to add a new condition to the “And” group.

      click-plus-button-to-add-condition

      CodeRush adds the “Node kind”.

      added-node-kind

    • Click the first “Node kind” and choose the Visibility item from the list.

      node-kind

    • Click the “enter a value” text box and choose Private from the list.

      set-value-to-private

  • Set the second Node kind to Enum.

    node-kind-enum

  • Configure sorting (optional) or leave it as is.

    sorting-group

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

    save-and-close-window

  • In the following code, place the caret anywhere in the class body.

using System;

public class TestClass
{
    // Field.
    private int fieldName;

    // Event.
    public event EventHandler EventName;

    // Method.
    private void MethodName()
    {

    }

    // Property.
    public int PropertyName { get; set; }

    // Enumerator.    
    private enum Numbers { One, Two, Three, Four };
}
  • Press Ctrl+. or Ctrl+~ to invoke the Code Actions Menu. Select Organize Members and press Enter.

    organize-new-rule