Create Case Blocks from Enum

Generates Case statements for each element of the current enum. Places the cursor on the first generated Case block, and drops markers on other Case blocks, if any.

Availability

Available from the context menu or via shortcuts:

  • when the cursor is placed on a reference to an enum.

Examples

enum MyEnum
{
    Element1,
    Element2,
    Element3
}
public void TestMethod()
{
    MyEnum enumVar = GetEnumElement();            
}
Enum MyEnum
    Element1
    Element2
    Element3
End Enum
Public Sub TestMethod()
    Dim enumVar As MyEnum = GetEnumElement()
End Sub

Result:

enum MyEnum
{
    Element1,
    Element2,
    Element3
}
public void TestMethod()
{
    MyEnum enumVar = GetEnumElement();
    switch (enumVar)
    {
        case CreateCaseBlocksFromEnum.MyEnum.Element1:

        break;
        case CreateCaseBlocksFromEnum.MyEnum.Element2:

        break;
        case CreateCaseBlocksFromEnum.MyEnum.Element3:

        break;
    }
}
Enum MyEnum
    Element1
    Element2
    Element3
End Enum
Public Sub TestMethod()
    Dim enumVar As MyEnum = GetEnumElement()
    Select Case enumVar
        Case CreateCaseBlocksFromEnum.MyEnum.Element1

        Case CreateCaseBlocksFromEnum.MyEnum.Element2

        Case CreateCaseBlocksFromEnum.MyEnum.Element3

    End Select
End Sub