Skip to main content

Namespace References Settings

  • 2 minutes to read

You can configure the Sort Namespace References and Optimize Namespace References features for C# and Visual Basic code on the Editor | All Languages | Namespace References options page.

Settings

Refer to the Configuration Options topic for information on how to access this page.

The “Namespace References” page contains the following settings:

Sort Namespace References

This option allows you to specify namespaces sorting order. CodeRush can sort namespaces by length (default mode) or alphabetically.

The following screencast shows the “Sort Namespace References” code formatter that sorts namespace references by length:

Sort

Note

CodeRush moves alias to the end of the namespace reference list after sorting is applied.

Place “System” References First

Specifies whether “System” namespace references are always on top after CodeRush applies any sorting. This option is initially disabled.

The screencast below shows how CodeRush places “System” references on the top when the alphabetical sorting is applied for “Sort Namespace References”:

System

Group References by First Qualifier

This option allows you to group namespace references by first qualifier (for example, System or DevExpress) when CodeRush sorts namespace references by length. CodeRush also sorts the order of the first qualifiers by length except ‘System’, if the “Place ‘System’ references first” option is enabled.

System

Apply Sorting When Optimizing References

This option allows you to disable or enable namespace reference sorting for the “Optimize Namespace References” refactoring.

If “Apply sorting when optimizing references” is disabled, this refactoring only removes unused namespace references.

Never Remove Following References

You can prevent the “Optimize Namespace References” refactoring from removing unused namespace references. For this, add namespace reference(s) to the “Never remove following references” list. This list contains “System” and “System.Linq” namespace references by default.

The following screencast shows the “Optimize Namespace References” refactoring that leaves the unused “System.Drawing” reference in a file:

System