Skip to main content

How to: Create a Rule

  • 2 minutes to read

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

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

    organize-members-page

  2. Click Add Rule to create a new rule.

    add-rule-button

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

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

    rule-name

  4. 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.

  5. 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

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

    sorting-group

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

    save-and-close-window

  8. 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 };
    }
    
  9. Press Ctrl+. or Ctrl+~ to invoke the Code Actions Menu. Select Organize Members and press Enter.

    organize-new-rule