Skip to content

Commit 3bb0be9

Browse files
KonHjoncham
authored andcommitted
[corlib] Fix Type.GetInterface() to find implemented interface when "ignoreCase: true" is used (mono#7464)
Fixes mono#6579
1 parent 194102d commit 3bb0be9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

mcs/class/corlib/Test/System/TypeTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4886,6 +4886,30 @@ public void NullFullNameForSpecificGenericTypes()
48864886
}
48874887
}
48884888

4889+
// https://github.com/mono/mono/issues/6579
4890+
[Test]
4891+
public void GetInterfaceCaseInsensitiveTest()
4892+
{
4893+
var type = typeof(Dictionary<string, object>);
4894+
4895+
Assert.NotNull (
4896+
type.GetInterface ("System.Collections.IDictionary", false),
4897+
"strict named interface must be found (ignoreCase = false)"
4898+
);
4899+
Assert.NotNull (
4900+
type.GetInterface ("System.Collections.IDictionary", true),
4901+
"strict named interface must be found (ignoreCase = true)"
4902+
);
4903+
Assert.Null (
4904+
type.GetInterface ("System.Collections.Idictionary", false),
4905+
"interface, named in mixed case, must not be found (ignoreCase = false)"
4906+
);
4907+
Assert.NotNull (
4908+
type.GetInterface ("System.Collections.Idictionary", true),
4909+
"interface, named in mixed case, must be found (ignoreCase = true)"
4910+
);
4911+
}
4912+
48894913
interface Bug59738Interface<T> {
48904914
}
48914915

mcs/class/referencesource/mscorlib/system/rttype.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,9 +3413,12 @@ public override Type GetInterface(String fullname, bool ignoreCase)
34133413

34143414
#if MONO
34153415
List<RuntimeType> list = null;
3416+
var nameComparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
34163417
foreach (RuntimeType t in GetInterfaces ()) {
3417-
if (t.Name != name)
3418-
continue;
3418+
3419+
if (!String.Equals(t.Name, name, nameComparison)) {
3420+
continue;
3421+
}
34193422

34203423
if (list == null)
34213424
list = new List<RuntimeType> (2);

0 commit comments

Comments
 (0)