coderushforroslyn-402265-getting-started-examples-organize-members-how-to-group-members-by-member-type-name.md
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.
Open the Editor | All Languages | Organize Members options page to configure the Organize Member.
Click Add Rule to add a rule for the ICommand auto-implemented properties.
Change the suggested rule name to “ICommand properties” and press Enter to apply the change.
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.
Note
The Rule priority setting does not affect the rule order specified in the rule set.
This section describes how to specify a condition to group auto-implemented properties by the type name.
In the “Group by” section, click the “+” button to add a new condition to the “And” group.
Repeat the previous step to add the third “Node kind”.
Click the first “Node Kind” and choose the “Member type name” item from the list.
Type “ICommand” in the “enter a value” text box and press Enter to apply the change.
Set the second “node kind” to “Property”. For this, click “enter a value” text box and choose the “Property” item from the list.
Set the last “node kind” to “Auto-implemented property”. Click “Member” and choose the corresponding item from the list.
Click Apply and OK to save the changes and close the Organize Members options page.
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.
CodeRush groups auto-implemented properties of the ICommand type according to the specified rule.
See Also