Skip to main content
All docs
V22.2

How to: Group Members by Member Type Name

  • 3 minutes to read

Organize Members can group members by the member type name (the property/field type and method return type, etc.). This example shows how to group auto-implemented properties by the ICommand type.

Add an ICommand Properties Rule to a Rule Set

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

    organize-members-page

  2. Click Add Rule to add a rule for the ICommand auto-implemented properties.

    click-add-rule

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

    Note

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

  3. Change the suggested rule name to “ICommand properties” and press Enter to apply the change.

    type-icommand-properties-rule-name

Customize the Rule

Change the Rule Priority

The Rule priority setting allows Organize Members to separate different kinds of members. For example, split auto-implemented properties of a certain type from other auto-implemented properties. Set the Rule Priority to High priority to allow Organize Members to create the ICommand properties group.

icommand-high-rule-priority

Note

The Rule priority setting does not affect the rule order specified in the rule set.

Configure Grouping

This section describes how to specify a condition to group auto-implemented properties by the type name.

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

  2. Repeat the previous step to add the third “Node kind”.

    add-third-node-kind

  3. Click the first “Node Kind” and choose the “Member type name” item from the list.

    set-node-kind-to-member-type-name

  4. Type “ICommand” in the “enter a value” text box and press Enter to apply the change.

    type-icommand-in-text-box

  5. Set the second “node kind” to “Property”. For this, click “enter a value” text box and choose the “Property” item from the list.

    set-node-kind-to-property

  6. Set the last “node kind” to “Auto-implemented property”. Click “Member” and choose the corresponding item from the list.

    node-kind-auto-implemented

    The condition for the “ICommand properties” rule looks as follows:

    icommand-properties-grouping

    Note

    Organize Members also allows you to use Contains, Starts with string operations and RegEx expressions to group members.

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

Run Organize Members

This section shows how to apply the ICommand properties rule.

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

using System;
using System.Windows.Input;

namespace WpfApp1.Folder
{
    class CodePlacesMenuViewModel : ItemViewModelBase
    {
        bool autoHide;

        private void SetProperty<T>(ref T autoHide, T value, string v, object onAutoHideChanged)
        {
            throw new NotImplementedException();
        }
        public ICommand ExpandAllCommand { get; set; }

        public bool AutoHide {
            get => autoHide;
            set => SetProperty(ref autoHide, value, nameof(AutoHide), OnAutoHideChanged);
        }
        public ICommand CollapseAllCommand { get; set; }
        public object OnAutoHideChanged { get; private set; }
        public ICommand AutoHideBtnCommand { get; set; }
    }
}

Press Ctrl+. or Ctrl+~ to invoke the Code Actions Menu. Select Organize Members and press Enter.

apply-icommand-properties-rule

CodeRush groups auto-implemented properties of the ICommand type according to the specified rule.

See Also