ObservableHashSet<T> ObservableHashSet(Of T) Class

Definition

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>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging
Public Class ObservableHashSet(Of T)
    Inherits ISet(Of T)
    Implements IReadOnlyCollection(Of T), IEnumerable(Of T), IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging
Type Parameters
T

The type of elements in the hash set.

Inheritance
System.ObjectSystem.Object
ObservableHashSet<T>ObservableHashSet(Of T)
Implements
System.Collections.Generic.IReadOnlyCollection<T>System.Collections.Generic.IReadOnlyCollection(Of T) System.Collections.Generic.IEnumerable<T>System.Collections.Generic.IEnumerable(Of T) System.Collections.IEnumerableSystem.Collections.IEnumerable

Constructors

ObservableHashSet() 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()
Public Sub New

ObservableHashSet(IEnumerable) ObservableHashSet(IEnumerable(Of 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)
Public Sub New(collection As IEnumerable(Of T))
Parameters
collection
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection whose elements are copied to the new set.

ObservableHashSet(IEnumerable, IEqualityComparer) ObservableHashSet(IEnumerable(Of T), IEqualityComparer(Of 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)
Public Sub New(collection As IEnumerable(Of T), comparer As IEqualityComparer(Of T))
Parameters
collection
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection whose elements are copied to the new set.

comparer
System.Collections.Generic.IEqualityComparer<T> System.Collections.Generic.IEqualityComparer(Of T)

The System.Collections.Generic.IEqualityComparer<T> implementation to use when comparing values in the set, or null to use the default System.Collections.Generic.IEqualityComparer<T> implementation for the set type.

ObservableHashSet(IEqualityComparer) ObservableHashSet(IEqualityComparer(Of 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)
Public Sub New(comparer As IEqualityComparer(Of T))
Parameters
comparer
System.Collections.Generic.IEqualityComparer<T> System.Collections.Generic.IEqualityComparer(Of T)

The System.Collections.Generic.IEqualityComparer<T> implementation to use when comparing values in the set, or null to use the default System.Collections.Generic.IEqualityComparer<T> implementation for the set type.

Properties

Comparer Comparer

Gets the System.Collections.Generic.IEqualityComparer<T> object that is used to determine equality for the values in the set.

public virtual IEqualityComparer<T> Comparer { get; }
Public Overridable ReadOnly Property Comparer As IEqualityComparer(Of T)
Value
System.Collections.Generic.IEqualityComparer<T> System.Collections.Generic.IEqualityComparer(Of T)

Count Count

Gets the number of elements that are contained in the hash set.

public virtual int Count { get; }
Public Overridable ReadOnly Property Count As Integer
Value
System.Int32 System.Int32

IsReadOnly IsReadOnly

Gets a value indicating whether the hash set is read-only.

public virtual bool IsReadOnly { get; }
Public Overridable ReadOnly Property IsReadOnly As Boolean
Value
System.Boolean System.Boolean

Methods

Add(T) Add(T)

Adds the specified element to the hash set.

public virtual bool Add(T item)
Public Overridable Function Add(item As T) As Boolean
Parameters
item
T T

The element to add to the set.

Returns
System.Boolean System.Boolean

true if the element is added to the hash set; false if the element is already present.

Clear() Clear()

Removes all elements from the hash set.

public virtual void Clear()
Public Overridable Sub Clear

Contains(T) Contains(T)

Determines whether the hash set object contains the specified element.

public virtual bool Contains(T item)
Public Overridable Function Contains(item As T) As Boolean
Parameters
item
T T

The element to locate in the hash set.

Returns
System.Boolean System.Boolean

True if the hash set contains the specified element; otherwise, false.

CopyTo(T[]) CopyTo(T())

Copies the elements of the hash set to an array.

public virtual void CopyTo(T[] array)
Public Overridable Sub CopyTo(array As T())
Parameters
array
T[] 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[], Int32) CopyTo(T(), Int32)

Copies the elements of the hash set to an array, starting at the specified array index.

public virtual void CopyTo(T[] array, int arrayIndex)
Public Overridable Sub CopyTo(array As T(), arrayIndex As Integer)
Parameters
array
T[] 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
System.Int32 System.Int32

The zero-based index in array at which copying begins.

CopyTo(T[], Int32, Int32) CopyTo(T(), Int32, Int32)

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)
Public Overridable Sub CopyTo(array As T(), arrayIndex As Integer, count As Integer)
Parameters
array
T[] 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
System.Int32 System.Int32

The zero-based index in array at which copying begins.

count
System.Int32 System.Int32

The number of elements to copy to array.

ExceptWith(IEnumerable) ExceptWith(IEnumerable(Of T))

Removes all elements in the specified collection from the hash set.

public virtual void ExceptWith(IEnumerable<T> other)
Public Overridable Sub ExceptWith(other As IEnumerable(Of T))
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection of items to remove from the current hash set.

GetEnumerator() GetEnumerator()

Returns an enumerator that iterates through the hash set.

public virtual HashSet<T>.Enumerator GetEnumerator()
Public Overridable Function GetEnumerator As HashSet(Of T).Enumerator
Returns
System.Collections.Generic.HashSet.Enumerator<> System.Collections.Generic.HashSet.Enumerator(Of )

An enumerator for the hash set.

IntersectWith(IEnumerable) IntersectWith(IEnumerable(Of 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)
Public Overridable Sub IntersectWith(other As IEnumerable(Of T))
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

IsProperSubsetOf(IEnumerable) IsProperSubsetOf(IEnumerable(Of T))

Determines whether the hash set is a proper subset of the specified collection.

public virtual bool IsProperSubsetOf(IEnumerable<T> other)
Public Overridable Function IsProperSubsetOf(other As IEnumerable(Of T)) As Boolean
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

Returns
System.Boolean System.Boolean

True if the hash set is a proper subset of other; otherwise, false.

IsProperSupersetOf(IEnumerable) IsProperSupersetOf(IEnumerable(Of T))

Determines whether the hash set is a proper superset of the specified collection.

public virtual bool IsProperSupersetOf(IEnumerable<T> other)
Public Overridable Function IsProperSupersetOf(other As IEnumerable(Of T)) As Boolean
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

Returns
System.Boolean System.Boolean

True if the hash set is a proper superset of other; otherwise, false.

IsSubsetOf(IEnumerable) IsSubsetOf(IEnumerable(Of T))

Determines whether the hash set is a subset of the specified collection.

public virtual bool IsSubsetOf(IEnumerable<T> other)
Public Overridable Function IsSubsetOf(other As IEnumerable(Of T)) As Boolean
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

Returns
System.Boolean System.Boolean

True if the hash set is a subset of other; otherwise, false.

IsSupersetOf(IEnumerable) IsSupersetOf(IEnumerable(Of T))

Determines whether the hash set is a superset of the specified collection.

public virtual bool IsSupersetOf(IEnumerable<T> other)
Public Overridable Function IsSupersetOf(other As IEnumerable(Of T)) As Boolean
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

Returns
System.Boolean System.Boolean

True if the hash set is a superset of other; otherwise, false.

OnCollectionChanged(NotifyCollectionChangedEventArgs) OnCollectionChanged(NotifyCollectionChangedEventArgs)

Raises the CollectionChanged event.

protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Protected Overridable Sub OnCollectionChanged(e As NotifyCollectionChangedEventArgs)
Parameters
e
NotifyCollectionChangedEventArgs NotifyCollectionChangedEventArgs

Details of the change.

OnPropertyChanged(PropertyChangedEventArgs) OnPropertyChanged(PropertyChangedEventArgs)

Raises the PropertyChanged event.

protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
Protected Overridable Sub OnPropertyChanged(e As PropertyChangedEventArgs)
Parameters
e
PropertyChangedEventArgs PropertyChangedEventArgs

Details of the property that changed.

OnPropertyChanging(PropertyChangingEventArgs) OnPropertyChanging(PropertyChangingEventArgs)

Raises the PropertyChanging event.

protected virtual void OnPropertyChanging(PropertyChangingEventArgs e)
Protected Overridable Sub OnPropertyChanging(e As PropertyChangingEventArgs)
Parameters
e
PropertyChangingEventArgs PropertyChangingEventArgs

Details of the property that is changing.

Overlaps(IEnumerable) Overlaps(IEnumerable(Of 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)
Public Overridable Function Overlaps(other As IEnumerable(Of T)) As Boolean
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

Returns
System.Boolean System.Boolean

True if the hash set and other share at least one common element; otherwise, false.

Remove(T) Remove(T)

Removes the specified element from the hash set.

public virtual bool Remove(T item)
Public Overridable Function Remove(item As T) As Boolean
Parameters
item
T T

The element to remove.

Returns
System.Boolean System.Boolean

True if the element is successfully found and removed; otherwise, false.

RemoveWhere(Predicate) RemoveWhere(Predicate(Of T))

Removes all elements that match the conditions defined by the specified predicate from the hash set.

public virtual int RemoveWhere(Predicate<T> match)
Public Overridable Function RemoveWhere(match As Predicate(Of T)) As Integer
Parameters
match
System.Predicate<T> System.Predicate(Of T)

The System.Predicate<T> delegate that defines the conditions of the elements to remove.

Returns
System.Int32 System.Int32

The number of elements that were removed from the hash set.

SetEquals(IEnumerable) SetEquals(IEnumerable(Of T))

Determines whether the hash set and the specified collection contain the same elements.

public virtual bool SetEquals(IEnumerable<T> other)
Public Overridable Function SetEquals(other As IEnumerable(Of T)) As Boolean
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

Returns
System.Boolean System.Boolean

True if the hash set is equal to other; otherwise, false.

SymmetricExceptWith(IEnumerable) SymmetricExceptWith(IEnumerable(Of 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)
Public Overridable Sub SymmetricExceptWith(other As IEnumerable(Of T))
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

ToBindingList() ToBindingList()

Returns an implementation that stays in sync with this collection.

public virtual BindingList<T> ToBindingList()
Public Overridable Function ToBindingList As BindingList(Of T)
Returns
BindingList<T> BindingList(Of T)

The binding list.

TrimExcess() 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()
Public Overridable Sub TrimExcess

UnionWith(IEnumerable) UnionWith(IEnumerable(Of 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)
Public Overridable Sub UnionWith(other As IEnumerable(Of T))
Parameters
other
System.Collections.Generic.IEnumerable<T> System.Collections.Generic.IEnumerable(Of T)

The collection to compare to the current hash set.

Events

CollectionChanged CollectionChanged

Occurs when the contents of the hash set changes.

public virtual event NotifyCollectionChangedEventHandler CollectionChanged
Public Overridable Event CollectionChanged As NotifyCollectionChangedEventHandler

PropertyChanged PropertyChanged

Occurs when a property of this hash set (such as Count) changes.

public virtual event PropertyChangedEventHandler PropertyChanged
Public Overridable Event PropertyChanged As PropertyChangedEventHandler

PropertyChanging PropertyChanging

Occurs when a property of this hash set (such as Count) is changing.

public virtual event PropertyChangingEventHandler PropertyChanging
Public Overridable Event PropertyChanging As PropertyChangingEventHandler

Explicit Interface Implementations

ICollection.Add(T) System.Collections.Generic.ICollection.Add(T)

void ICollection<T>.Add(T item)
Sub System.Collections.Generic.ICollection<T>.Add(item As T) Implements ICollection(Of T).Add
Parameters
item
T T

IEnumerable.GetEnumerator() System.Collections.Generic.IEnumerable.GetEnumerator()

IEnumerator<T> IEnumerable<T>.GetEnumerator()
Function System.Collections.Generic.IEnumerable<T>.GetEnumerator As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
Returns
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator(Of T)

IEnumerable.GetEnumerator() System.Collections.IEnumerable.GetEnumerator()

IEnumerator IEnumerable.GetEnumerator()
Function System.Collections.IEnumerable.GetEnumerator As IEnumerator Implements IEnumerable.GetEnumerator
Returns
System.Collections.IEnumerator System.Collections.IEnumerator