Skip to content

VB -> C#: Explicit interface implementation adds a setter for readonly property. #813

Closed
@Yozer

Description

@Yozer

VB.Net input code

Public Interface IUser
    ReadOnly Property Username As String
End Interface

Public Class User
    Implements IUser

    Public Property Nick As String Implements IUser.Username
        Get
            Throw New NotImplementedException
        End Get
        Set
            Throw New NotImplementedException
        End Set
    End Property

End Class

Erroneous output

    public interface IUser
    {
        string Username { get; }
    }

    public class User : IUser
    {
        string IUser.Username
        {
            get
            {
                throw new NotImplementedException();
            }

            set
            {
                throw new NotImplementedException();
            }
        }

        public string Nick { get => ((IUser)this).Username; set => ((IUser)this).Username = value; }
    }

    static class Module1
    {
        public static void Main()
        {
            var test1 = "" ?? () => 5;
            var test2 = () => 4 ?? () => 5;
        }
    }

Expected output

    public interface IUser
    {
        string Username { get; }
    }

    public class User : IUser
    {
        public string Nick
        {
            get
            {
                throw new NotImplementedException();
            }

            set
            {
                throw new NotImplementedException();
            }
        }

        string IUser.Username => Nick;
    }

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.

Could the fix be to always keep the getter/setter in a class property and just generate delegate calls from all explicit interface implementations?

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