icsharpcode / CodeConverter

Convert code from C# to VB.NET and vice versa using Roslyn
https://icsharpcode.github.io/CodeConverter/
MIT License
840 stars 218 forks source link

VB -> C#: supporting variable for WithEvents gets non-existent type in some cases #1055

Open TymurGubayev opened 11 months ago

TymurGubayev commented 11 months ago

This happens when the names of a class and its namespace only differ in case (NS1 vs Ns1).

VB.Net input code

Imports NS1

Public Class TestNameSpaceSameNameAsClass
    Public WithEvents ins As NS1.Ns1
End Class

Namespace Global.NS1
    Public Class Ns1
    End Class
End Namespace

Erroneous output

using System.Runtime.CompilerServices;

namespace NS1
{
    public class NS1
    {
    }
}

public class TestNameSpaceSameNameAsClass
{
    private NS1 _ins; //error: this class doesn't exist

    public virtual NS1 ins
    {
        [MethodImpl(MethodImplOptions.Synchronized)]
        get
        {
            return _ins;
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        set
        {
            _ins = value;
        }
    }
}

Expected output

using System.Runtime.CompilerServices;

namespace NS1
{
    public class NS1
    {
    }
}

public class TestNameSpaceSameNameAsClass
{
    private NS1.Ns1 _ins;

    public virtual NS1.Ns1 ins
    {
        [MethodImpl(MethodImplOptions.Synchronized)]
        get
        {
            return _ins;
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        set
        {
            _ins = value;
        }
    }
}

Details