Skip to content

C# -> VB: Simple assignment expression inside a constructor expression body converts to using CSharpImpl.__Assign. #1105

Open
@RussellSmith2

Description

@RussellSmith2

Input code

internal class NameGenerator
{
    private readonly Func<string, string> _getValidIdentifier;
	
    private NameGenerator(Func<string, string> getValidIdentifier) => _getValidIdentifier = getValidIdentifier;
}

Erroneous output

Friend Class NameGenerator
    Private ReadOnly _getValidIdentifier As Func(Of String, String)

    Private Sub New(getValidIdentifier As Func(Of String, String))
        CSharpImpl.__Assign(_getValidIdentifier, getValidIdentifier)
    End Sub

    Private Class CSharpImpl
        <Obsolete("Please refactor calling code to use normal Visual Basic assignment")>
        Shared Function __Assign(Of T)(ByRef target As T, value As T) As T
            target = value
            Return value
        End Function
    End Class
End Class

Expected output

Friend Class NameGenerator
    Private ReadOnly _getValidIdentifier As Func(Of String, String)

    Private Sub New(getValidIdentifier As Func(Of String, String))
      _getValidIdentifier = getValidIdentifier
    End Sub
End Class

Details

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