Skip to content

Commit

Permalink
Merge pull request #1155 from gaschd/issue-1154-wrong-nested-types-co…
Browse files Browse the repository at this point in the history
…nversion

Fixed node name search for case-sensitive namespaces and types
  • Loading branch information
GrahamTheCoder authored Nov 9, 2024
2 parents a232218 + 9f15f5b commit bb5c35f
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CodeConverter/CSharp/CommonConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ private static TypeSyntax WithDeclarationNameCasing(TypeSyntax syntax, ITypeSymb

return syntax.ReplaceNodes(syntax.DescendantNodes().OfType<CSSyntax.IdentifierNameSyntax>(), (oldNode, _) =>
{
var originalName = originalNames.FirstOrDefault(on => string.Equals(on, oldNode.ToString(), StringComparison.OrdinalIgnoreCase));
string oldNodeStr = oldNode.ToString();
var originalName = originalNames.FirstOrDefault(on => string.Equals(on, oldNodeStr, StringComparison.Ordinal)) ??
originalNames.FirstOrDefault(on => string.Equals(on, oldNodeStr, StringComparison.OrdinalIgnoreCase));
return originalName != null ? ValidSyntaxFactory.IdentifierName(originalName) : oldNode;
});
}
Expand Down
97 changes: 97 additions & 0 deletions Tests/CSharp/CaseSensitivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,103 @@ protected virtual System.Web.UI.WebControls.Button btnOk
}");
}

[Fact]
public async Task Issue1154_NamespaceAndClassSameNameDifferentCaseAsync()
{
await TestConversionVisualBasicToCSharpAsync(@"
Imports System
Namespace Issue1154
<CaseSensitive1.Casesensitive1.TestDummy>
Public Class UpperLowerCase
End Class
<Casesensitive2.CaseSensitive2.TestDummy>
Public Class LowerUpperCase
End Class
<CaseSensitive3.CaseSensitive3.TestDummy>
Public Class SameCase
End Class
End Namespace
Namespace CaseSensitive1
Public Class Casesensitive1
Public Class TestDummyAttribute
Inherits Attribute
End Class
End Class
End Namespace
Namespace Casesensitive2
Public Class CaseSensitive2
Public Class TestDummyAttribute
Inherits Attribute
End Class
End Class
End Namespace
Namespace CaseSensitive3
Public Class CaseSensitive3
Public Class TestDummyAttribute
Inherits Attribute
End Class
End Class
End Namespace
",
@"
using System;
namespace Issue1154
{
[CaseSensitive1.Casesensitive1.TestDummy]
public partial class UpperLowerCase
{
}
[Casesensitive2.CaseSensitive2.TestDummy]
public partial class LowerUpperCase
{
}
[CaseSensitive3.CaseSensitive3.TestDummy]
public partial class SameCase
{
}
}
namespace CaseSensitive1
{
public partial class Casesensitive1
{
public partial class TestDummyAttribute : Attribute
{
}
}
}
namespace Casesensitive2
{
public partial class CaseSensitive2
{
public partial class TestDummyAttribute : Attribute
{
}
}
}
namespace CaseSensitive3
{
public partial class CaseSensitive3
{
public partial class TestDummyAttribute : Attribute
{
}
}
}
");
}



}

0 comments on commit bb5c35f

Please sign in to comment.