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

Fixed node name search for case-sensitive namespaces and types #1155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing issue - doesn't need to be fixed here:
It's a bit odd that this uses ToString on the nodes rather than using the identifier text directly. It's probably the same in the implementation, but it's weird this relies on it.

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
{
}
}
}
");
}



}
Loading