Class ObservableHashSet<T>
- Namespace
- Microsoft.EntityFrameworkCore.ChangeTracking
- Assembly
- Microsoft.EntityFrameworkCore.dll
A hash set that implements the interfaces required for Entity Framework to use notification based change tracking for a collection navigation property.
public class ObservableHashSet<T> : ISet<T>, ICollection<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging
Type Parameters
T
The type of elements in the hash set.
- Inheritance
-
ObservableHashSet<T>
- Implements
-
ISet<T>ICollection<T>IEnumerable<T>
- Inherited Members
Remarks
See Local views of tracked entities in EF Core for more information and examples.
Constructors
ObservableHashSet()
Initializes a new instance of the ObservableHashSet<T> class that is empty and uses the default equality comparer for the set type.
public ObservableHashSet()
ObservableHashSet(IEnumerable<T>)
Initializes a new instance of the ObservableHashSet<T> class that uses the default equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.
public ObservableHashSet(IEnumerable<T> collection)
Parameters
collection
IEnumerable<T>The collection whose elements are copied to the new set.
ObservableHashSet(IEnumerable<T>, IEqualityComparer<T>)
Initializes a new instance of the ObservableHashSet<T> class that uses the specified equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.
public ObservableHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
Parameters
collection
IEnumerable<T>The collection whose elements are copied to the new set.
comparer
IEqualityComparer<T>The IEqualityComparer<T> implementation to use when comparing values in the set, or null to use the default IEqualityComparer<T> implementation for the set type.
ObservableHashSet(IEqualityComparer<T>)
Initializes a new instance of the ObservableHashSet<T> class that is empty and uses the specified equality comparer for the set type.
public ObservableHashSet(IEqualityComparer<T> comparer)
Parameters
comparer
IEqualityComparer<T>The IEqualityComparer<T> implementation to use when comparing values in the set, or null to use the default IEqualityComparer<T> implementation for the set type.
Properties
Comparer
Gets the IEqualityComparer<T> object that is used to determine equality for the values in the set.
public virtual IEqualityComparer<T> Comparer { get; }
Property Value
Count
Gets the number of elements that are contained in the hash set.
public virtual int Count { get; }
Property Value
IsReadOnly
Gets a value indicating whether the hash set is read-only.
public virtual bool IsReadOnly { get; }
Property Value
Methods
Add(T)
Adds the specified element to the hash set.
public virtual bool Add(T item)
Parameters
item
TThe element to add to the set.
Returns
Clear()
Removes all elements from the hash set.
public virtual void Clear()
Contains(T)
Determines whether the hash set object contains the specified element.
public virtual bool Contains(T item)
Parameters
item
TThe element to locate in the hash set.
Returns
CopyTo(T[])
Copies the elements of the hash set to an array.
public virtual void CopyTo(T[] array)
Parameters
array
T[]The one-dimensional array that is the destination of the elements copied from the hash set. The array must have zero-based indexing.
CopyTo(T[], int)
Copies the elements of the hash set to an array, starting at the specified array index.
public virtual void CopyTo(T[] array, int arrayIndex)
Parameters
array
T[]The one-dimensional array that is the destination of the elements copied from the hash set. The array must have zero-based indexing.
arrayIndex
intThe zero-based index in array at which copying begins.
CopyTo(T[], int, int)
Copies the specified number of elements of the hash set to an array, starting at the specified array index.
public virtual void CopyTo(T[] array, int arrayIndex, int count)
Parameters
array
T[]The one-dimensional array that is the destination of the elements copied from the hash set. The array must have zero-based indexing.
arrayIndex
intThe zero-based index in array at which copying begins.
count
intThe number of elements to copy to array.
ExceptWith(IEnumerable<T>)
Removes all elements in the specified collection from the hash set.
public virtual void ExceptWith(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection of items to remove from the current hash set.
GetEnumerator()
Returns an enumerator that iterates through the hash set.
public virtual HashSet<T>.Enumerator GetEnumerator()
Returns
- HashSet<T>.Enumerator
An enumerator for the hash set.
IntersectWith(IEnumerable<T>)
Modifies the current hash set to contain only elements that are present in that object and in the specified collection.
public virtual void IntersectWith(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
IsProperSubsetOf(IEnumerable<T>)
Determines whether the hash set is a proper subset of the specified collection.
public virtual bool IsProperSubsetOf(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
Returns
IsProperSupersetOf(IEnumerable<T>)
Determines whether the hash set is a proper superset of the specified collection.
public virtual bool IsProperSupersetOf(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
Returns
IsSubsetOf(IEnumerable<T>)
Determines whether the hash set is a subset of the specified collection.
public virtual bool IsSubsetOf(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
Returns
IsSupersetOf(IEnumerable<T>)
Determines whether the hash set is a superset of the specified collection.
public virtual bool IsSupersetOf(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
Returns
OnCollectionChanged(NotifyCollectionChangedEventArgs)
Raises the CollectionChanged event.
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
e
NotifyCollectionChangedEventArgsDetails of the change.
OnPropertyChanged(PropertyChangedEventArgs)
Raises the PropertyChanged event.
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
Parameters
e
PropertyChangedEventArgsDetails of the property that changed.
OnPropertyChanging(PropertyChangingEventArgs)
Raises the PropertyChanging event.
protected virtual void OnPropertyChanging(PropertyChangingEventArgs e)
Parameters
e
PropertyChangingEventArgsDetails of the property that is changing.
Overlaps(IEnumerable<T>)
Determines whether the current System.Collections.Generic.HashSet`1 object and a specified collection share common elements.
public virtual bool Overlaps(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
Returns
Remove(T)
Removes the specified element from the hash set.
public virtual bool Remove(T item)
Parameters
item
TThe element to remove.
Returns
RemoveWhere(Predicate<T>)
Removes all elements that match the conditions defined by the specified predicate from the hash set.
public virtual int RemoveWhere(Predicate<T> match)
Parameters
match
Predicate<T>The Predicate<T> delegate that defines the conditions of the elements to remove.
Returns
- int
The number of elements that were removed from the hash set.
SetEquals(IEnumerable<T>)
Determines whether the hash set and the specified collection contain the same elements.
public virtual bool SetEquals(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
Returns
SymmetricExceptWith(IEnumerable<T>)
Modifies the current hash set to contain only elements that are present either in that object or in the specified collection, but not both.
public virtual void SymmetricExceptWith(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
TrimExcess()
Sets the capacity of the hash set to the actual number of elements it contains, rounded up to a nearby, implementation-specific value.
public virtual void TrimExcess()
UnionWith(IEnumerable<T>)
Modifies the hash set to contain all elements that are present in itself, the specified collection, or both.
public virtual void UnionWith(IEnumerable<T> other)
Parameters
other
IEnumerable<T>The collection to compare to the current hash set.
Events
CollectionChanged
Occurs when the contents of the hash set changes.
public event NotifyCollectionChangedEventHandler? CollectionChanged
Event Type
PropertyChanged
Occurs when a property of this hash set (such as Count) changes.
public event PropertyChangedEventHandler? PropertyChanged
Event Type
PropertyChanging
Occurs when a property of this hash set (such as Count) is changing.
public event PropertyChangingEventHandler? PropertyChanging