Skip to content

Commit

Permalink
[corlib] Fix Type.GetInterface() to find implemented interface when "…
Browse files Browse the repository at this point in the history
…ignoreCase: true" is used (mono#7464)

Fixes mono#6579
  • Loading branch information
KonH authored and joncham committed Mar 9, 2018
1 parent 194102d commit 3bb0be9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 24 additions & 0 deletions mcs/class/corlib/Test/System/TypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4886,6 +4886,30 @@ public void NullFullNameForSpecificGenericTypes()
}
}

// https://github.com/mono/mono/issues/6579
[Test]
public void GetInterfaceCaseInsensitiveTest()
{
var type = typeof(Dictionary<string, object>);

Assert.NotNull (
type.GetInterface ("System.Collections.IDictionary", false),
"strict named interface must be found (ignoreCase = false)"
);
Assert.NotNull (
type.GetInterface ("System.Collections.IDictionary", true),
"strict named interface must be found (ignoreCase = true)"
);
Assert.Null (
type.GetInterface ("System.Collections.Idictionary", false),
"interface, named in mixed case, must not be found (ignoreCase = false)"
);
Assert.NotNull (
type.GetInterface ("System.Collections.Idictionary", true),
"interface, named in mixed case, must be found (ignoreCase = true)"
);
}

interface Bug59738Interface<T> {
}

Expand Down
7 changes: 5 additions & 2 deletions mcs/class/referencesource/mscorlib/system/rttype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3413,9 +3413,12 @@ public override Type GetInterface(String fullname, bool ignoreCase)

#if MONO
List<RuntimeType> list = null;
var nameComparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
foreach (RuntimeType t in GetInterfaces ()) {
if (t.Name != name)
continue;

if (!String.Equals(t.Name, name, nameComparison)) {
continue;
}

if (list == null)
list = new List<RuntimeType> (2);
Expand Down

0 comments on commit 3bb0be9

Please sign in to comment.