Code Elements Order Options

Top  Previous  Next

 C#   VB.NET   VB6   VB5   VBA 

The Code Elements Order section of the Team Options tab allows you to customize the Sort Code Elements feature, defining how to sort code elements for each supported language:

CodeElementsOrder

First, you select a parent code element kind (Class, Module, etc.), because you may want different orders in each kind of parent code element.

Then, you create a list of children code elements with some characteristics (kind, name or declaration meeting a condition, access and context) whose sorting priority can be changed with the buttons to move up and down. When the Sort Code Elements feature is executed on a file of code, MZ-Tools iterates recursively its code elements. For each code element, it searches in the list (for the corresponding parent code element kind) the first item whose kind, name/declaration condition, access and context matches the actual values for the code element, getting a sorting priority. Then, code elements are sorted recursively according to their sorting priority.

To create a child code element you use the following window:

ChildCodeElement

In this window you enter the following properties of the child code element:

  • Kind: it can be field, constant, method, property, event, etc., depending on the parent code element kind (for example, a class can contain events, but a module can't).
     
  • Condition: you can set a condition that the Name or Declaration of the child code element must meet. For example, you may want to sort first the methods that start by "Form_".
     
  • Access: it can be "any" or some combination of access values (public, private, etc.).
     
  • Context: it depends on the child code element kind. In most cases the context is a combination of modifiers used in the code element declaration (such as static/Shared, etc.)
     
  • Code Region (only Visual Studio): if you want that all the children code elements with the same sorting priority to be surrounded by a region (#region) created by MZ-Tools after sorting the code elements, enter its name here. Note: this will cause that existing regions that you may have created by hand are lost.
     
  • Sorting Criteria: normally you will want to sort all the children code elements with the same kind, access and context by code element name, but for code elements that return a type you may want to sort them by type name. For some code element kinds (such as constants), you may want to preserve the existing order.

Here are some examples of sorting for a class parent code element kind:

  • If you want all properties to be sorted before all methods (independently of their access), create these children code elements:

Kind

Access

Context

Property

Any

Any

Method

Any

Any

  • If you want all public members to be sorted before all non-public members, create these children code elements:

Kind

Access

Context

Property

Public

Any

Method

Public

Any

Property

Any

Any

Method

Any

Any

  • If you want all static (Shared in VB.NET) methods to be sorted before non-static methods, create these children code elements:

Kind

Access

Context

Method

Any

With the 'static' modifier

Method

Any

Without the 'static' modifier

See Also:

Sort Code Elements