Skip to content

VB -> C#: indexed property assignment can implicitly convert in VB, needs cast in C# #610

@jamesmanning

Description

@jamesmanning

Input code

Public Class Class1
    Public Property SomeProp(ByVal index As Integer) As Single
        Get
            Return 1.5
        End Get
        Set(ByVal Value As Single)
        End Set
    End Property

    Public Sub Foo()
        Dim someDecimal As Decimal = 123.0
        SomeProp(123) = someDecimal
    End Sub
End Class

Erroneous output

    public class Class1
    {
        public float get_SomeProp(int index)
        {
            return 1.5F;
        }

        public void set_SomeProp(int index, float value)
        {
        }

        public void Foo()
        {
            decimal someDecimal = 123.0M;
            this.set_SomeProp(123, someDecimal);
        }

Expected output

AFAICT we just need the explicit cast or some other way of converting to the target type at the call sites of the indexed property setter. I put a cast here, but the right thing may be one of the Conversions calls or something.

    public class Class1
    {
        public float get_SomeProp(int index)
        {
            return 1.5F;
        }

        public void set_SomeProp(int index, float value)
        {
        }

        public void Foo()
        {
            decimal someDecimal = 123.0M;
            this.set_SomeProp(123, (float)someDecimal);
        }

Details

VS extension 8.1.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    VB -> C#Specific to VB -> C# conversion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions