Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

C# -> VB: interface conversion not occuring correctly #125

Closed
MatthewDancz opened this issue May 25, 2018 · 5 comments
Closed

C# -> VB: interface conversion not occuring correctly #125

MatthewDancz opened this issue May 25, 2018 · 5 comments
Assignees
Labels
C# -> VB Specific to C# -> VB conversion

Comments

@MatthewDancz
Copy link

MatthewDancz commented May 25, 2018

Input code

    public class ToBeDisplayed : iDisplay
    {
        public string Name { get; set; }

        public void DisplayName()
        {
            Console.WriteLine(Name);
        }
    }

    public interface iDisplay
    {
        string Name { get; set; }
        void DisplayName();
    }

Erroneous output

 Public Class ToBeDisplayed
        Implements iDisplay

        Public Property Name As String

        Public Sub DisplayName()
            Console.WriteLine(Name)
        End Sub
    End Class

    Interface iDisplay
        Private Property Name As String
        Sub DisplayName()
    End Interface

Expected output

Public Class ToBeDisplayed
    Implements iDisplay

    Public Property Name As String Implements iDisplay.Name

    Public Sub DisplayName() Implements iDisplay.DisplayName
        Console.WriteLine(Name)
    End Sub
End Class

Interface iDisplay
    Property Name As String
    Sub DisplayName()
End Interface

Details

Product in use: web converter v5.7.0.0 and Visual Studio 2017 v15.7.2

Thoughts: My thought is that the converter doesn't understand C# Get and Set methods for properties, but that doesn't explain why I receive compiler errors saying that my implementing class doesn't implement DisplayName() in the erroneous code.

@siegfriedpammer
Copy link
Member

The only thing that's missing in the VB version is the implements clause... Other than that auto properties use that syntax in VB.

@MatthewDancz
Copy link
Author

Oh okay, I don't use VB. I did notice that it wasn't bringing over the implements clause, and that iDisplay string property converted to a private Property from C# to VB. In C# all interface properties are considered public, and you cannot set the access modifier to anything other than that. Hopefully these are easy fixes.

@GrahamTheCoder
Copy link
Member

The implements clause is there. The private modifier on the interface member is definitely incorrect, so I'll fix that. I've updated the expected output correspondingly

@GrahamTheCoder GrahamTheCoder self-assigned this May 25, 2018
@GrahamTheCoder GrahamTheCoder added the C# -> VB Specific to C# -> VB conversion label May 25, 2018
@siegfriedpammer
Copy link
Member

In VB each member that implements an interface member needs to have a corresponding implements clause: see https://github.com/dotnet/vblang/blob/master/spec/type-members.md

So the expected output would be Public Property Name As String Implements iDisplay.Name for the property and Public Sub DisplayName() Implements iDisplay.DisplayName for the method, I believe...

Quote from the spec:

Methods, events, and properties can implement interface members. To implement an interface member, a member declaration specifies the Implements keyword and lists one or more interface members.

@GrahamTheCoder
Copy link
Member

@siegfriedpammer Ah thanks, didn't know that was required in VB. I've updated the expected output. I'll have a look at fixing both things sometime soon hopefully, though as always if someone else is keen to PR a fix, just post here before you get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# -> VB Specific to C# -> VB conversion
Projects
None yet
Development

No branches or pull requests

3 participants