Skip to main content

Declare Struct

  • 2 minutes to read
In This Article

Generates a structure for a current reference. Creates text fields for the constructor parameters and drops a marker onto the initial structure reference.

The Declare Struct code provider also declares structure 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 structure;
  • when the edit cursor or caret is on a reference to a non-existent structure constructor.

#Example

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

Result:

public struct MyStruct
{
    public string Name { get; set; }

    public void SetValue(int param1)
    {
        throw new NotImplementedException();
    }
    public MyStruct(string param1, int param2)
    {

    }
}
class TestClass
{
    private void TestMethod()
    {
        MyStruct objVar = new MyStruct("StructName", 25);
        objVar.Name = "ObjName";
        objVar.SetValue(15);
    }
}
Public Structure MyStructure
    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 Structure
Public Class TestClass
    Private Sub TestMethod()
        Dim objVar As MyStructure = New MyStructure("StructName", 25)
        objVar.Name = "ObjName"
        objVar.SetValue(15)
    End Sub
End Class