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

VB -> C#: Invalid access modifiers added to explicit interface implementation when VB method/property is non-public. #819

Closed
Yozer opened this issue Jan 27, 2022 · 0 comments · Fixed by #820
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@Yozer
Copy link
Member

Yozer commented Jan 27, 2022

VB.Net input code

Public Interface IFoo
    Function ExplicitFunc() As Integer
    Sub ExplicitSub()
    Property ExplicitProperty As String
End Interface

Public Class Foo
    Implements IFoo

    Friend Function ExplicitFunc() As Integer Implements IFoo.ExplicitFunc
    End Function

    Private Sub ExplicitSub() Implements IFoo.ExplicitSub
    End Sub

    Protected Friend Property ExplicitPropertyDifferentName As String Implements IFoo.ExplicitProperty
End Class

Erroneous output

    public interface IFoo
    {
        int ExplicitFunc();
        void ExplicitSub();

        string ExplicitProperty { get; set; }
    }

    public class Foo : IFoo
    {
        internal int ExplicitFunc()
        {
            return default;
        }

        void IFoo.ExplicitSub()
        {
        }

        protected internal string IFoo.ExplicitProperty { get; set; }
        protected internal string ExplicitPropertyDifferentName { get => ((IFoo)this).ExplicitProperty; set => ((IFoo)this).ExplicitProperty = value; }
    }

Few problems here:

  1. Interface implementation internal int ExplicitFunc() cannot have an internal modifier.
  2. Interface implementation void IFoo.ExplicitSub() should have generated delegating private method. Otherwise calls like Me.ExplicitSub() will fail to compile.
  3. protected internal string IFoo.ExplicitProperty { get; set; } similar problems with properties.

Expected output

    public interface IFoo
    {
        int ExplicitFunc();
        void ExplicitSub();

        string ExplicitProperty { get; set; }
    }

    public class Foo : IFoo
    {
        int IFoo.ExplicitFunc()
        {
            return default;
        }

        internal int ExplicitFunc() => ((IFoo)this).ExplicitFunc();

        void IFoo.ExplicitSub()
        {
        }

        private void ExplicitSub() => ((IFoo)this).ExplicitSub();

        string IFoo.ExplicitProperty { get; set; }
        protected internal string ExplicitPropertyDifferentName { get => ((IFoo)this).ExplicitProperty; set => ((IFoo)this).ExplicitProperty = value; }
    }

Details

  • Product in use: VS extension
  • Version in use: 8.4.4.0
  • Did you see it working in a previous version, which?
  • Any other relevant information to the issue, or your interest in contributing a fix.
    I will create PR with a possible fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant