From f1cb639c58eadd79db5de2348b555aceb189abdb Mon Sep 17 00:00:00 2001 From: gaschd Date: Wed, 6 Nov 2024 11:17:05 +0100 Subject: [PATCH 1/3] Added test case for issue #1154 where namespaces and classes have different casing but same name --- Tests/CSharp/CaseSensitivityTests.cs | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/Tests/CSharp/CaseSensitivityTests.cs b/Tests/CSharp/CaseSensitivityTests.cs index 21755a437..6d5d34873 100644 --- a/Tests/CSharp/CaseSensitivityTests.cs +++ b/Tests/CSharp/CaseSensitivityTests.cs @@ -61,6 +61,103 @@ protected virtual System.Web.UI.WebControls.Button btnOk }"); } + [Fact] + public async Task Issue1154_NamespaceAndClassSameNameDifferentCaseAsync() + { + await TestConversionVisualBasicToCSharpAsync(@" +Imports System + +Namespace Issue1154 + + Public Class UpperLowerCase + End Class + + + Public Class LowerUpperCase + End Class + + + 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.TestDummyAttribute] + public partial class UpperLowerCase + { + } + + [Casesensitive2.CaseSensitive2.TestDummyAttribute] + 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 + { + } + } +} +"); + } + } \ No newline at end of file From 4d9be4395ff14b453cd87abf82871719fe4bbeed Mon Sep 17 00:00:00 2001 From: gaschd Date: Wed, 6 Nov 2024 22:56:33 +0100 Subject: [PATCH 2/3] Changing test case output formatting --- Tests/CSharp/CaseSensitivityTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/CSharp/CaseSensitivityTests.cs b/Tests/CSharp/CaseSensitivityTests.cs index 6d5d34873..383464187 100644 --- a/Tests/CSharp/CaseSensitivityTests.cs +++ b/Tests/CSharp/CaseSensitivityTests.cs @@ -107,25 +107,25 @@ End Namespace ", @" using System; - + namespace Issue1154 { - [CaseSensitive1.Casesensitive1.TestDummyAttribute] + [CaseSensitive1.Casesensitive1.TestDummy] public partial class UpperLowerCase { } - - [Casesensitive2.CaseSensitive2.TestDummyAttribute] + + [Casesensitive2.CaseSensitive2.TestDummy] public partial class LowerUpperCase { } - + [CaseSensitive3.CaseSensitive3.TestDummy] public partial class SameCase { } } - + namespace CaseSensitive1 { public partial class Casesensitive1 @@ -135,7 +135,7 @@ public partial class TestDummyAttribute : Attribute } } } - + namespace Casesensitive2 { public partial class CaseSensitive2 @@ -145,7 +145,7 @@ public partial class TestDummyAttribute : Attribute } } } - + namespace CaseSensitive3 { public partial class CaseSensitive3 From 9f15f5b89e6bb19f057d0681cc2274952860288a Mon Sep 17 00:00:00 2001 From: gaschd Date: Wed, 6 Nov 2024 23:04:49 +0100 Subject: [PATCH 3/3] WithDeclarationNameCasing tries to match nodes case sensitive first, then case insensitive --- CodeConverter/CSharp/CommonConversions.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CodeConverter/CSharp/CommonConversions.cs b/CodeConverter/CSharp/CommonConversions.cs index 3b540339e..8636907f2 100644 --- a/CodeConverter/CSharp/CommonConversions.cs +++ b/CodeConverter/CSharp/CommonConversions.cs @@ -229,7 +229,9 @@ private static TypeSyntax WithDeclarationNameCasing(TypeSyntax syntax, ITypeSymb return syntax.ReplaceNodes(syntax.DescendantNodes().OfType(), (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; }); }