Add to Interface

Purpose

This Code Provider adds a member to an interface implemented by the current class. Use this Code Provider to make the member obligatory for all interface implementations.

Availability

Available when the caret is on a non-overridden member, assuming the class implements one or more interfaces.

Usage

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

    Note

    The blinking cursor shows the caret's position at which the Code Provider is available.

    interface IPerson {
        string FullName { get; set; }
    }
    class Customer : IPerson {
        public string FullName { get; set; }
        public string MobilePhone { get; set; }
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Add to <Interface Name> Interface from the menu. In this case, the menu item will be Add to IPerson Interface.

After execution, the Code Provider adds the required member to the interface.

interface IPerson {
    string MobilePhone { get; set; }
    string FullName { get; set; }
}
class Customer : IPerson {
    public string FullName { get; set; }
    public string MobilePhone { get; set; }
}