All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
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: Group Members by Member Name

  • 3 minutes to read

Organize Members allows you to group members (properties, methods, etc.) by the member name. This example shows how to create, configure, and apply rules for Form_Load, Form events, and Button click event handlers.

Add Event Handlers Rules to a Rule Set

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

    Organize Members Page

  • Click Add Rule to add a rule for the Form_Load event handler.

    Add Rule

  • Type "Form_Load" in the Rule name text box.

    Rule Name

  • Click Move Up to change the rule's position in the rule set.
    When you run Organize Members, CodeRush changes the order of type members to correspond to the order of rules in the rule set. Change the "Form_Load" rule's position, as shown in the screenshot below. The "Form_Load" event handler follows constructors in a class.

    Form Load Rule Order

    NOTE

    Organize Members applies rules according to the specified order in the rule set.

  • Repeat the previous steps to create and position "Form events" and "Button click event handlers" rules in the rule set.

    Rules Position

Customize Rules

  • Select the Form_Load rule.

    Form Load Rule

  • Focus the Node kind item in the Group section.

    Focus Mode Kind

  • Switch Kind to Name.

    Switch Kind

  • Click And to create the And group.

    Add the And Group

  • Expand the new And group. Specify the following condition: set the Name to Regex, type the "\w*Form\w*_Load\w*" regular expression in the text box, and set the Node kind to Method.

    Form Load Regex

    The "\w*Form\w*_Load\w*" regular expression allows Organize Members to group event handlers whose name contain the "*Form*_Load*" mask.

    NOTE

    Organize Members also allows you to use Equals, Contains, and StartsWith string operations to group members.

  • Click Apply to save changes.

  • Select the "Form events" rule and create the And group, as described in the previous steps.

    Form Events Group

  • Specify the following condition for the And group: set the Name to Regex, type the "\w*Form\w*_\w*" regular expression in the text box, and set the Node kind to Method.

    Form Events Group

  • Select the "Button click event handlers" rule and create the And group, as described above. Specify the following criteria: set the Name to Regex, type the "\w*Button\w*_click\w*" regular expression in the text box, and set the Node kind to Method

    Button Click Condition

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

Run Organize Members

This section shows how to apply Form_Load, Form events, and Button click rules.

In the following code, place the caret anywhere in the class body:

using System;
using System.Windows.Forms;

namespace WinFormsApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {

        }
    }
}

Press Ctrl+. or Ctrl+~ to invoke the Code Actions Menu and select Organize Members.

Apply Rules

CodeRush groups event handlers according to the specified rule's order.

See Also