Organize Members Settings

  • 6 min to read

You can access the Organize Members settings on the Editor | All Languages | Organize Members options page.

Use the following settings to configure a member organization rule:

Empty Line Count Between Members

This setting specifies empty line count CodeRush must insert above and below members. The screencast below shows how to specify "Empty line count between members" for fields.

Rule Priority

CodeRush applies member rules based on the Rule priority option value, and then by rule order. The following Rule priority values are available:

  • Low
  • Normal
  • High

The Rule priority option allows you to group different kinds of members prior to other rules, for example, explicit interface implementations.

Example

Set the Rule priority option for explicit interface implementations to Low and run Organize Members.

namespace Project {

    public interface IPerson {

        void PersonInfo();
        void SaveToDB();
    }

    public class Person : IPerson {

        int Age { get; set; }
        string Id { get; set; }
        string Name { get; set; }

        void IPerson.PersonInfo() {

        }
        protected void PersonInfo(SerializationInfo info, StreamingContext context) {
            if (info == null)
                return;
            Name = info.GetString(nameof(Name));
            Age = info.GetInt32(nameof(Age));
            Id = info.GetString(nameof(Id));
        }
        void IPerson.SaveToDB() {

        }
        void SaveToDB() {

        }
    }
}

Change the Rule priority option for explicit interface implementations to High and run Organize Members:

namespace Project {

    public interface IPerson {

        void PersonInfo();
        void SaveToDB();
    }

    public class Person : IPerson {

        void IPerson.PersonInfo() {

        }
        void IPerson.SaveToDB() {

        }

        int Age { get; set; }
        string Id { get; set; }
        string Name { get; set; }

        protected void PersonInfo(SerializationInfo info, StreamingContext context) {
            if (info == null)
                return;
            Name = info.GetString(nameof(Name));
            Age = info.GetInt32(nameof(Age));
            Id = info.GetString(nameof(Id));
        }

        void SaveToDB() {

        }
    }
}

Grouping Rules

Grouping rules allows you to configure what kind of members CodeRush groups together by the rule.

CodeRush can add members into groups by the following criteria:

  • Kind - allows you to choose the kind of member for which CodeRush should create a group.
  • Visibility - allows you to specify members' visibility criteria (private, protected, protected internal, internal, and public).

  • Modifier - allows you to specify an access modifier criteria to group members (abstract, read-only, override, sealed, static, virtual, and extern).

  • HasAttributes - use this setting to specify the member attributes.

  • ParentHasAttributes - specify this setting if you need CodeRush to take attributes into account for parent types.
  • Parent Kind - allows you to choose a parent type for which CodeRush should create a group.

  • IsExplicitInterfaceImplementor - choose this setting to allow CodeRush to create a group for explicit interface members.

  • IsInterfaceImplementor - choose this setting to allow CodeRush to create a group for both explicit and implicit interface members.
  • IsEventHandler - specify this setting if you need CodeRush to create a group for event handlers.

You can use Add, Or, and Not conditions to create grouping criteria.

Refer to the How to Create a Rule example for information on how to configure grouping.

Sorting Rules

You can configure the sort order of members within a group for each member organization rule in the Sorting rules section.

CodeRush can sort group items by:

  • Name
  • Kind
  • Access Modifier (abstract, read-only, override, sealed, static, virtual, extern)
  • Visibility
  • Parameter count
  • Explicit interface name
  • Interface name
  • Event handler (IsEventHandler mode)

You can also specify the sort order: ascending or descending.

Wrap Distinct Groups in Regions

The Wrap distinct groups in regions option allows CodeRush to wrap sorted groups in dynamic regions with built-in variables.

CodeRush provides the following built-in variables in the region name:

Example

To create regions for properties with different visibility:

  • Add the Properties rule to the rule set. See the Member Organization topic for more information.

  • Change "Sort by" from Name to Visibility and enable the Wrap distinct groups in regions option.

  • Type "{Visibility} properties" in the region name text box.

    OrganizeMembersPage

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

  • Run the Organize Members.

Insert Empty Line above and below Members

Enable the corresponding option to insert an empty line above and below all organized members.

The following screencast shows this feature in action.

Specify Empty Line Count between Groups

Use the "Empty line count between groups" setting to specify how many empty lines CodeRush should place between different code sections. The empty line count default value is 1.

If you want to reduce the empty line count between groups, enable the "Remove existing line breaks" options to remove blank lines between members.

For example, the code below has 2 empty lines between groups. You can use the default "Empty line count between groups" value to change the empty line count to 1.

Skip Initialized Fields

CodeRush provides an option to skip initialized fields.

In some cases, field initialization order can be important (for example, one field depends on another field). If you change this order in code, it can lead to an exception when a class is created. To avoid this, the "Skip Initialized fields" option is enabled by default. CodeRush does not move initialized fields into the 'fields' group.