Skip to main content

Declare Class

  • 2 minutes to read
In This Article

Generates a class for a current reference to a non-existent class. Creates text fields for the constructor parameters and drops a marker onto the initial class reference.

The Declare Class code provider also declares class members called from the initial code.

#Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on a reference to a non-existent class.
  • when the edit cursor or caret is on a reference to a non-existent class constructor.

#Example

class TestClass
{
    private void TestMethod()
    {ClassA objVar = new ClassA("ClassName", 25);
        objVar.Name = "ObjName";
        objVar.SetValue(15);
    }
}
Public Class TestClass
    Private Sub TestMethod()
        Dim objVar As ClassA = New ClassA("ClassName", 25)
        objVar.Name = "ObjName"
        objVar.SetValue(15)
    End Sub
End Class

Result:

public class ClassA
{
    public string Name { get; set; }
    public void SetValue(int param1)
    {
        throw new NotImplementedException();
    }
    public ClassA(string param1, int param2)
    {

    }
}
class TestClass
{
    private void TestMethod()
    {
        ClassA objVar = new ClassA("ClassName", 25);
        objVar.Name = "ObjName";
        objVar.SetValue(15);
    }
}
Public Class ClassA
    Public Property Name() As String
        Get
            Throw New NotImplementedException()
        End Get
        Set(ByVal value As String)
            Throw New NotImplementedException()
        End Set
    End Property
    Public Sub SetValue(ByVal param1 As Integer)
        Throw New System.NotImplementedException()

    End Sub
    Public Sub New(ByVal param1 As String, ByVal param2 As Integer)

    End Sub
End Class
Public Class TestClass
    Private Sub TestMethod()
        Dim objVar As ClassA = New ClassA("ClassName", 25)
        objVar.Name = "ObjName"
        objVar.SetValue(15)
    End Sub
End Class