diff --git a/tests/xharness/Extensions.cs b/tests/xharness/Extensions.cs index 0fa00b7210..6a86822630 100644 --- a/tests/xharness/Extensions.cs +++ b/tests/xharness/Extensions.cs @@ -119,23 +119,5 @@ namespace xharness // // This makes it abundantly clear that the intention is to not await 'DoSomething', and no warnings will be shown either. } - - public static IEnumerable Distinct (this IEnumerable collection, Func comparer) - { - var list = new List (); - foreach (var item in collection) { - bool found = false; - for (var i = 0; i < list.Count; i++) { - if (comparer (list [i], item)) { - found = true; - break; - } - } - if (found) - continue; - list.Add (item); - yield return item; - } - } } } diff --git a/tests/xharness/Simulators.cs b/tests/xharness/Simulators.cs index 595da7e341..041342e449 100644 --- a/tests/xharness/Simulators.cs +++ b/tests/xharness/Simulators.cs @@ -99,7 +99,7 @@ namespace xharness SelectNodes ("/MTouch/Simulator/AvailableDevicePairs/SimDevicePair"). Cast (). // There can be duplicates, so remove those. - Distinct ((a, b) => a.Attributes ["Gizmo"].InnerText == b.Attributes ["Gizmo"].InnerText && a.Attributes ["Companion"].InnerText == b.Attributes ["Companion"].InnerText); + Distinct (new SimulatorXmlNodeComparer ()); foreach (XmlNode sim in sim_device_pairs) { available_device_pairs.Add (new SimDevicePair () { @@ -324,6 +324,19 @@ namespace xharness }; } + class SimulatorXmlNodeComparer : IEqualityComparer + { + public bool Equals (XmlNode a, XmlNode b) + { + return a["Gizmo"].InnerText == b["Gizmo"].InnerText && a["Companion"].InnerText == b["Companion"].InnerText; + } + + public int GetHashCode (XmlNode node) + { + return node["Gizmo"].InnerText.GetHashCode () ^ node["Companion"].InnerText.GetHashCode (); + } + } + class SimulatorEnumerable : IEnumerable, IAsyncEnumerable { public Simulators Simulators;