Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
jamesmanning opened this issue Aug 16, 2020 · 0 comments
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@jamesmanning
Copy link

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

@jamesmanning jamesmanning added the VB -> C# Specific to VB -> C# conversion label Aug 16, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant