Skip to content

Instantly share code, notes, and snippets.

@dejanstojanovic
Last active August 29, 2015 14:16
Show Gist options
  • Save dejanstojanovic/4a5bb6e9444bcd805148 to your computer and use it in GitHub Desktop.
Save dejanstojanovic/4a5bb6e9444bcd805148 to your computer and use it in GitHub Desktop.
/// <summary>
/// Compares elements of two IEnumerables of same type regardless of element order in both Ienumrables
/// </summary>
/// <typeparam name="T">Type of IEnumerables to compare</typeparam>
/// <param name="Compare">IEnumareble to compare with</param>
/// <param name="CompareTo">IEnumerable to compare to</param>
/// <returns></returns>
public static bool Equals<T>(this IEnumerable<T> Compare, IEnumerable<T> CompareTo)
{
return new HashSet<T>(Compare ?? new List<T>()).SetEquals(CompareTo ?? new List<T>());
}
/// <summary>
/// Checks is IEnumerable is superset of another IEnumerable
/// </summary>
/// <typeparam name="T">Type of IEnumerables to compare</typeparam>
/// <param name="Superset">IEnumerable to check within</param>
/// <param name="Subset">IEnumerable to search for in superset IEnumerable of type T</param>
/// <returns></returns>
public static bool Contains<T>(this IEnumerable<T> Superset, IEnumerable<T> Subset)
{
return new HashSet<T>(Superset ?? new List<T>()).IsSupersetOf(Subset ?? new List<T>());
}
/// <summary>
/// Checks is IEnumerable is subset of another IEnumerable
/// </summary>
/// <typeparam name="T">Type of IEnumerables to compare</typeparam>
/// <param name="Subset">IEnumerable to search for in superset IEnumerable of type T</param>
/// <param name="Superset">IEnumerable to check within</param>
/// <returns></returns>
public static bool ContainedIn<T>(this IEnumerable<T> Subset, IEnumerable<T> Superset)
{
return new HashSet<T>(Subset ?? new List<T>()).IsSubsetOf(Superset ?? new List<T>());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment