Back to Devexpress

Add to Interface

coderushforroslyn-116586-coding-assistance-code-providers-add-to-interface.md

latest1.3 KB
Original Source

Add to Interface

  • Aug 03, 2020
  • 2 minutes to read

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.

  2. Press 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.

csharp
interface IPerson {
    string MobilePhone { get; set; }
    string FullName { get; set; }
}
class Customer : IPerson {
    public string FullName { get; set; }
    public string MobilePhone { get; set; }
}
vb
Interface IPerson
    Property MobilePhone As String
    Property FullName() As String
End Interface
Class Customer
    Implements IPerson
    Public Property FullName() As String Implements IPerson.FullName
    Public Property MobilePhone() As String Implements IPerson.MobilePhone
End Class