Skip to content

VB -> C#: Avoid creating code blocks for each case when converting Select Case #1244

Description

@circular17

When converting a Select Case statement, each outcome is wrapped in braces, creating a code block. This adds unnecessary indentation.

For example:

    Private Shared Function d1mach(i As Integer) As Double
        Select Case i
            Case 1
                Return 2.2250738585072014E-308 ' the smallest positive magnitude.
            Case 2
                Return Double.MaxValu ' the largest magnitude.
        End Select
        Return 0
    End Function

Is converted as:

        private static double d1mach(int i)
        {
            switch (i)
            {
                case 1:
                    {
                        return 2.2250738585072014E-308d; // the smallest positive magnitude.
                    }
                case 2:
                    {
                        return double.MaxValue; // the largest magnitude.
                    }
            }
            return 0d;
        }

Proposed solution
When no variable is created in the case branch, avoid creating a code block. The output code would be:

        private static double d1mach(int i)
        {
            switch (i)
            {
                case 1:
                    return 2.2250738585072014E-308d; // the smallest positive magnitude.
                case 2:
                    return double.MaxValue; // the largest magnitude.
            }
            return 0d;
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions