Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public static System.Collections.Immutable.ImmutableArray<
> CastUp<TDerived>(System.Collections.Immutable.ImmutableArray<TDerived> items) where TDerived : class?, T { throw null; }
public System.Collections.Immutable.ImmutableArray<T> Clear() { throw null; }
public bool Contains(T item) { throw null; }
public bool Contains(T item, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
public void CopyTo(int sourceIndex, T[] destination, int destinationIndex, int length) { }
public void CopyTo(T[] destination) { }
public void CopyTo(T[] destination, int destinationIndex) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ public bool Contains(T item)
return this.IndexOf(item) >= 0;
}

/// <summary>
/// Determines whether the specified item exists in the array.
/// </summary>
/// <param name="item">The item to search for.</param>
/// <param name="equalityComparer">
/// The equality comparer to use in the search.
/// If <c>null</c>, <see cref="EqualityComparer{T}.Default"/> is used.
/// </param>
/// <returns><c>true</c> if an equal value was found in the array; <c>false</c> otherwise.</returns>
public bool Contains(T item, IEqualityComparer<T>? equalityComparer)
{
return this.IndexOf(item, equalityComparer) >= 0;
}

/// <summary>
/// Returns a new array with the specified value inserted at the specified position.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,24 @@ public void ContainsInt32(IEnumerable<int> source)
Assert.False(((ICollection<int>)array).Contains(notContained));
}

[Fact]
public void ContainsDivisibleEqualityComparer()
{
ImmutableArray<int> array = ImmutableArray.Create(1, 4, 3);
var divisibleComparer = new DelegateEqualityComparer<int>(equals: (x, y) => x % y == 0);
Assert.True(array.Contains(2, divisibleComparer));

array = ImmutableArray.Create(1, 5, 3);
Assert.False(array.Contains(2, divisibleComparer));
}

[Fact]
public void ContainsDefaultEqualityComparer()
{
ImmutableArray<int> array = ImmutableArray.Create(1, 2, 3);
Assert.True(array.Contains(2, null));
}

[Theory]
[MemberData(nameof(ContainsNullData))]
public void ContainsNull<T>(IEnumerable<T> source) where T : class
Expand Down