diff --git a/CodeConverter/CSharp/CommonConversions.cs b/CodeConverter/CSharp/CommonConversions.cs index 3b540339..8636907f 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; }); } diff --git a/Tests/CSharp/CaseSensitivityTests.cs b/Tests/CSharp/CaseSensitivityTests.cs index 21755a43..38346418 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.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 + { + } + } +} +"); + } + } \ No newline at end of file