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: Group Interface Implementations and Wrap them into Regions

  • 3 minutes to read

Organize Members can group explicit and implicit interface implementations and wrap them into regions according to the interface implementation rule. This example shows how to create, configure, and apply the interface implementations rule.

Add an Interface Implementations Rule to a Rule Set

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

    organize-members-rules-page

  • Click Add Rule to add a rule for interface implementations.

    add-rule

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

  • Change the suggested rule name to “Interface implementations” and press Enter to save the change.

    Type Rule Name

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

    OrganizeMembersPage

NOTE

Organize Members applies rules according to the specified order in the rule set and the Rule priority setting.

Customize the Rule

Change the Rule Priority

  • Set the Rule Priority setting to High priority to allow Organize Members to wrap interface implementations into regions. For information about this setting, see the following topic: Rule Priority

    specify-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 which is used to group interface implementations.

  • Select the “Interface implementations” rule in the rule list.

  • 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 Is interface implementor from the list.

    choose-is-interface-implementor

    The And group looks as follows:

    add-group

When you run Organize Members CodeRush analyzes all type’s members and checks the Is interface implementor condition to create an interface implementations group.

Configure Sorting

This section describes how to specify a condition which is used to sort interface implementation groups.

  • In the “Sort by” section, set the Sort by to InterfaceName. This allows Organize Members to sort interface implementation groups by interface name.

    sort-interface-name

  • Enable the Wrap distinct groups in regions option to activate wrapping of implicit and explicit interface implementations in regions.

    activate-region-wrapping

  • Type “{InterfaceName} implementations” in the region name text box.

    type-interface-name

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

Run Organize Members

This section shows how to apply the interface implementation rule.

In the following code, place the caret to any place in the class body.

using System.Drawing;

namespace ConsoleApp {

    interface IDimensions {
        float GetLength();
        float GetWidth();
    }

    interface IColor {
        Color GetBackgroundColor();
        Color GetForegroundColor();
    }

    public class Box : IDimensions, IColor {
        Color boxColor;
        float lengthInches;
        float widthInches;

        Box(float length, float width, Color color) {
            lengthInches = length;
            widthInches = width;
            boxColor = color;
        }

        float GetLength() {
            return lengthInches;
        }
        float IDimensions.GetLength() {
            return lengthInches;
        }
        float GetWidth() {
            return widthInches;
        }

        float IDimensions.GetWidth() {
            return widthInches;
        }

        public Color GetForegroundColor() {
            return boxColor;
        }
        public Color GetBackgroundColor() {
            return boxColor;
        }
    }
}

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

organize-implementations-result

CodeRush groups explicit and implicit interface implementations according to the specified rule and wraps these implementations into regions.

See Also