Skip to main content

Add XML Comments

  • 3 minutes to read

Purpose

Adds an XML comment to a member. If you use Add XML Comments for a method that overrides a base type’s method or implements an interface’s method, the Code Provider copies a base method’s XML comment.

If the target method has no base method or its base method has no XML comment, the code provider generates an empty XML comment with the correct structure.

Availability

Available when the caret is on a method’s name, property or constructor in its declaration.

Usage

  1. Place the caret on a member’s name in its declaration.

    interface ISampleInterface {
        /// <summary>
        /// This method is used to demonstrate the <strong>Add XML Comments</strong> feature
        /// </summary>
        /// <param name="param1">The first parameter</param>
        /// <param name="param2">The second parameter</param>
        /// <returns>The resulting string</returns>
        string SampleMethod(int param1, int param2);
    }
    class SampleClass : ISampleInterface {
        public string SampleMethod(int param1, int param2) {
            return String.Format($"{a}{b}");
        }
    }
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Add XML Comments from the menu.

After execution, the Code Provider creates an XML comment for the target member.

interface ISampleInterface {
    /// <summary>
    /// This method is used to demonstrate the <strong>Add XML Comments</strong> feature
    /// </summary>
    /// <param name="param1">The first number</param>
    /// <param name="param2">The second number</param>
    /// <returns>The resulting string</returns>
    string SampleMethod(int param1, int param2);
}
class SampleClass : ISampleInterface {
    /// <summary>
    /// This method is used to demonstrate the <strong>Add XML Comments</strong> feature
    /// </summary>
    /// <param name="param1">The first parameter</param>
    /// <param name="param2">The second parameter</param>
    /// <returns>The resulting string</returns>
    public string SampleMethod(int a, int b) {
        return String.Format($"{a}{b}");
    }
}