Skip to main content
A newer version of this page is available. .

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.

    OrganizeMembersPage

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

    OrganizeMembersPage

  • Type a rule name in the corresponding text box.

    OrganizeMembersPage

  • Click Move Up to change the rule's position in the rule set.
    When you run Organize Members, CodeRush changes the type's members order to correspond to the rules order in the rule set. Change the interface implementations rule’s position, as shown in the screenshot below, if you want interface implementations to follow indexers in a type.

    OrganizeMembersPage

NOTE

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

Customize the Rule

Change the Rule Priority

The Rule priority option allows Organize Members to separate different kinds of members. For example, split interface implementations from methods. Set the Rule Priority to High to allow Organize Members to create an interface implementations group.

OrganizeMembersPage

NOTE

The Rule priority option 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.

  • Focus the Node kind item.

  • Switch Kind to IsInterfaceImplementor.

  • Click And to create the And group.

  • Expand the newly-created And group to see the result.

When you run Organize Members CodeRush analyzes all type's members and checks the IsInterfaceImplementor 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.

  • Set the Sort by to InterfaceName. This allows Organize Members to sort interface implementation groups by interface name.

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

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

  • Click Apply to save changes or click OK to save changes and close the CodeRush configuration menu.

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 and select Organize Members.

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

See Also