Table of Contents

Class ExtensionMethodsSet

Namespace
NDepend.Helpers
Assembly
NDepend.API.dll

Provides a set of extension methods to optimize enumerables operations on set.

public static class ExtensionMethodsSet
Inheritance
ExtensionMethodsSet
Inherited Members

Methods (11)

Except<T>(IEnumerable<T>, HashSet<T>)

Produces the set difference of this seq and hashset. This method is an optimized version of Enumerable.Except<T>.

public static IEnumerable<T> Except<T>(this IEnumerable<T> seq, HashSet<T> hashset) where T : class

Parameters

seq IEnumerable<T>

A sequence of elements whose elements that are not also in hashset will be returned.

hashset HashSet<T>

An hashset of elements whose elements that also occur in seq will cause those elements to be removed from the returned sequence.

Returns

IEnumerable<T>

A sequence that contains the set difference of the elements of seq and hashset.

Type Parameters

T

The element type of the elements of the hashset and the sequence.

Remarks

This extension method has a O(seq.Count) time complexity.

Intersect<T>(HashSet<T>, HashSet<T>)

Produces the set of elements, intersection of this hashset and otherHashset. This method is an optimized version of Enumerable.Intersect<T>.

public static IEnumerable<T> Intersect<T>(this HashSet<T> hashset, HashSet<T> otherHashset)

Parameters

hashset HashSet<T>

An hashset of elements whose distinct elements that also appear in otherHashset will be returned.

otherHashset HashSet<T>

An hashset of elements whose distinct elements that also appear in hashset will be returned.

Returns

IEnumerable<T>

A sequence that contains the elements that form the set intersection of both hashsets.

Type Parameters

T

The code element type of the elements of the hashset and the sequence.

Remarks

This extension method has a O(otherHashset.Count) time complexity.

Intersect<T>(HashSet<T>, IEnumerable<T>)

Produces the set of elements, intersection of this hashset and seq. This method is an optimized version of Enumerable.Intersect<T>.

public static IEnumerable<T> Intersect<T>(this HashSet<T> hashset, IEnumerable<T> seq)

Parameters

hashset HashSet<T>

An hashset of elements whose distinct elements that also appear in seq will be returned.

seq IEnumerable<T>

A sequence of elements whose distinct elements that also appear in hashset will be returned.

Returns

IEnumerable<T>

A sequence that contains the elements that form the set intersection of the hashset and the sequence.

Type Parameters

T

The code element type of the elements of the hashset and the sequence.

Remarks

This extension method has a O(seq.Count) time complexity.

Intersect<T>(IEnumerable<T>, HashSet<T>)

Produces the set of elements, intersection of this seq and hashset. This method is an optimized version of Enumerable.Intersect<T>.

public static IEnumerable<T> Intersect<T>(this IEnumerable<T> seq, HashSet<T> hashset)

Parameters

seq IEnumerable<T>

A sequence of elements whose distinct elements that also appear in hashset will be returned.

hashset HashSet<T>

An hashset of elements whose distinct elements that also appear in seq will be returned.

Returns

IEnumerable<T>

A sequence that contains the elements that form the set intersection of the hashset and the sequence.

Type Parameters

T

The code element type of the elements of the hashset and the sequence.

Remarks

This extension method has a O(seq.Count) time complexity.

ToHashSetEx<T>(IEnumerable<T>)

Creates an hashset from a IEnumerable<T>.

public static HashSet<T> ToHashSetEx<T>(this IEnumerable<T> seq)

Parameters

seq IEnumerable<T>

An IEnumerable<T> to create an hashset from.

Returns

HashSet<T>

An hashset that contains the elements from the input sequence.

Type Parameters

T

The type of the elements of seq.

Remarks

This method exists since NDepend v2018.1.1 because the .NET Fx v4.7.2 introduces a ToHashSet() extension method with the same signature as the one in the NDepend.API. As a consequence ambiguous call errors are emitted by the compiler when using ToHashSet() in a .NET fx v4.7.2 (or upper) environment. ToHashSet() can still be used as a static method ExtensionMethodsSet.ToHashSet(...). To avoid any problem, a straightforward solution is to replace "ToHashSet()" with "ToHashSetEx()" in all your .ndproj and .ndrules textual files that contain your code queries and rules.

ToHashSetEx<T>(IEnumerable<T>, IEqualityComparer<T>)

Creates an hashset from a IEnumerable<T>.

public static HashSet<T> ToHashSetEx<T>(this IEnumerable<T> seq, IEqualityComparer<T> equalityComparer)

Parameters

seq IEnumerable<T>

An IEnumerable<T> to create an hashset from.

equalityComparer IEqualityComparer<T>

The equality comparer on elements.

Returns

HashSet<T>

An hashset that contains the elements from the input sequence.

Type Parameters

T

The type of the elements of seq.

Remarks

This method exists since NDepend v2018.1.1 because the .NET Fx v4.7.2 introduces a ToHashSet() extension method with the same signature as the one in the NDepend.API. As a consequence ambiguous call errors are emitted by the compiler when using ToHashSet() in a .NET fx v4.7.2 (or upper) environment. ToHashSet() can still be used as a static method ExtensionMethodsSet.ToHashSet(...). To avoid any problem, a straightforward solution is to replace "ToHashSet()" with "ToHashSetEx()" in all your .ndproj and .ndrules textual files that contain your code queries and rules.

ToHashSet<T>(IEnumerable<T>)

Creates an hashset from a IEnumerable<T>.

[Obsolete("Use ToHashSetEx() extension method instead to avoid conflict with the .NET Fx v4.7.2 ToHashSet() extension method with same signature")]
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq)

Parameters

seq IEnumerable<T>

An IEnumerable<T> to create an hashset from.

Returns

HashSet<T>

An hashset that contains the elements from the input sequence.

Type Parameters

T

The type of the elements of seq.

Remarks

The .NET Fx v4.7.2 introduces a ToHashSet() extension method with the same signature. As a consequence this method has been marked as obsolete since NDepend v2018.1.1 and it is advised to use ToHashSetEx<T>(IEnumerable<T>) instead, to avoid ambiguous call error emitted by the compiler.

ToHashSet<T>(IEnumerable<T>, IEqualityComparer<T>)

Creates an hashset from a IEnumerable<T>.

[Obsolete("Use ToHashSetEx() extension method instead to avoid conflict with the .NET Fx v4.7.2 ToHashSet() extension method with same signature")]
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq, IEqualityComparer<T> equalityComparer)

Parameters

seq IEnumerable<T>

An IEnumerable<T> to create an hashset from.

equalityComparer IEqualityComparer<T>

The equality comparer on elements.

Returns

HashSet<T>

An hashset that contains the elements from the input sequence.

Type Parameters

T

The type of the elements of seq.

Remarks

The .NET Fx v4.7.2 introduces a ToHashSet() extension method with the same signature. As a consequence this method has been marked as obsolete since NDepend v2018.1.1 and it is advised to use ToHashSetEx<T>(IEnumerable<T>, IEqualityComparer<T>) instead, to avoid ambiguous call error emitted by the compiler.

Union<T>(HashSet<T>, HashSet<T>)

Produces the set of elements, union of this thisHashset and otherHashset. This method is an optimized version of Enumerable.Union<T>.

public static IEnumerable<T> Union<T>(this HashSet<T> thisHashset, HashSet<T> otherHashset)

Parameters

thisHashset HashSet<T>

A sequence of elements whose distinct elements form the first set for the union.

otherHashset HashSet<T>

An hashset of elements whose distinct elements form the second set for the union.

Returns

IEnumerable<T>

A sequence that contains the elements that form the set union of both hashsets, excluding duplicates.

Type Parameters

T

The code element type of the elements of the hashset and the sequence.

Remarks

This extension method has a O(otherHashset.Count) time complexity.

Union<T>(HashSet<T>, IEnumerable<T>)

Produces the set of elements, union of this hashset and seq. This method is an optimized version of Enumerable.Union<T>.

public static IEnumerable<T> Union<T>(this HashSet<T> hashset, IEnumerable<T> seq)

Parameters

hashset HashSet<T>

An hashset of elements whose distinct elements form the first set for the union.

seq IEnumerable<T>

A sequence of elements whose distinct elements form the second set for the union.

Returns

IEnumerable<T>

A sequence that contains the elements that form the set union of the hashset and the sequence, excluding duplicates.

Type Parameters

T

The code element type of the elements of the hashset and the sequence.

Remarks

This extension method has a O(seq.Count) time complexity.

Union<T>(IEnumerable<T>, HashSet<T>)

Produces the set of elements, union of this seq and hashset. This method is an optimized version of Enumerable.Union<T>.

public static IEnumerable<T> Union<T>(this IEnumerable<T> seq, HashSet<T> hashset)

Parameters

seq IEnumerable<T>

A sequence of elements whose distinct elements form the second set for the union.

hashset HashSet<T>

An hashset of elements whose distinct elements form the first set for the union.

Returns

IEnumerable<T>

A sequence that contains the elements that form the set union of the sequence and the hashset, excluding duplicates.

Type Parameters

T

The code element type of the elements of the hashset and the sequence.

Remarks

This extension method has a O(seq.Count) time complexity.