Przeglądaj źródła

Added function to compare arrays

Kenric Nugteren 6 miesięcy temu
rodzic
commit
a9298e3319
1 zmienionych plików z 26 dodań i 0 usunięć
  1. 26 0
      InABox.Core/CoreUtils.cs

+ 26 - 0
InABox.Core/CoreUtils.cs

@@ -2734,6 +2734,32 @@ namespace InABox.Core
             list.Sort((a, b) => comparison(a).CompareTo(comparison(b)));
         }
 
+        /// <summary>
+        /// Compare the elements in this list to the other list, returning <see langword="true"/> if they have all the same
+        /// elements, regardless of order.
+        /// </summary>
+        public static bool CompareTo<T>(this IList<T> thisList, IList<T> list)
+        {
+            if(thisList.Count != list.Count)
+            {
+                return false;
+            }
+            return thisList.All(x => list.Contains(x));
+        }
+
+        /// <summary>
+        /// Compare the elements in this list to the other list, returning <see langword="true"/> if they have all the same
+        /// elements, regardless of order.
+        /// </summary>
+        public static bool CompareTo<T>(this IList<T> thisList, IList<T> list, IEqualityComparer<T> comparer)
+        {
+            if(thisList.Count != list.Count)
+            {
+                return false;
+            }
+            return thisList.All(x => list.Contains(x, comparer));
+        }
+
         #endregion
 
     }