Skip to main content

How to: Add a Comment to the Start of a Section

  • 2 minutes to read

Follow the steps below.

  1. Open the Editor | All Languages | Organize Members options page to configure the Member Organization rules feature.

    organize-members-page

  2. Select a rule (for example, “Fields”).

  3. Click the Comment button.

    comment-button

  4. You can change the suggested comment name, for example, to “Fields…” in the corresponding text box. Press Enter to apply the new region name.

    comment-text-field

    CodeRush shows the “Member section name” field set to “Fields” in the right part of the options page.

    Note

    The “Member section name” field allows CodeRush to insert a comment into a template expansion. The template should contain the “MemberHeader” string provider with the “Fields”, “Methods”, or “Properties” argument, depending on the member type for which you want to add a comment. When you expand, for example, one of the “p?type?” templates (“pb”, “ps”, and others), CodeRush adds this comment to fields.

  5. Click Apply to save changes or click OK to save changes and close the Organize Members options page.

  6. Place the caret in a class member in the code snippet below:

    namespace Ex
    {
        public class TestClass
        {
            private int age;
    
            //Properties...
            public int Age { get { return age; } }
            public string Name { get { return name; } }
    
            private string name;
        }   
    }
    
  7. Press Ctrl+. or Ctrl+~ to invoke the Code Actions Menu.

  8. Choose Organize Members from the menu and press Enter.

    add-comments-to-rule

CodeRush groups fields according to the Organize Members rules and creates the “Fields…” comment for fields.

See Also