Back to Devexpress

Add Missing Constructors

coderushforroslyn-116629-coding-assistance-code-providers-add-missing-constructors.md

latest1.4 KB
Original Source

Add Missing Constructors

  • Aug 03, 2020
  • 2 minutes to read

Purpose

Adds all constructors declared in the parent types to the current class. Use this Code Provider to add all required constructors at once.

Availability

Available when the caret is on the name of the class, assuming it misses one or more inherited constructors.

Usage

  1. Place the caret on a class name.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Add Missing Constructors from the menu.

After execution, the Code Provider adds all missing constructors to the class.

csharp
public class Person {
    public Person(string FullName) { }
    public Person(string FirstName, string LastName) { }
}
class Customer: Person {
    public Customer(string FullName) : base(FullName) {

    }

    public Customer(string FirstName, string LastName) : base(FirstName, LastName) {

    }
}
vb
Public Class Person
    Public Sub New(FullName As String)
    End Sub
    Public Sub New(FirstName As String, LastName As String)
    End Sub
End Class
Friend Class Customer
    Inherits Person
    Public Sub New(FullName As String)
        MyBase.New(FullName)

    End Sub

    Public Sub New(FirstName As String, LastName As String)
        MyBase.New(FirstName, LastName)

    End Sub
End Class