Table of Contents

Class UpcastingCollectionExtensions

Namespace
Garyon.Extensions.Upcasting
Assembly
Garyon.dll

Provides extensions for upcasting known collection types like IList<T>, IReadOnlyList<T>, etc.

public static class UpcastingCollectionExtensions
Inheritance
UpcastingCollectionExtensions
Inherited Members

Methods

UpcastCollection<TBase, TUp>(ICollection<TBase>)

Upcasts the given ICollection<T> into a collection of TUp instances.

public static ICollection<TUp> UpcastCollection<TBase, TUp>(this ICollection<TBase> source) where TUp : class, TBase

Parameters

source ICollection<TBase>

Returns

ICollection<TUp>

Type Parameters

TBase
TUp

Remarks

No validation is performed on whether all the elements are TUp. This method is unsafe and should be used on collections where it is known.

UpcastDictionary<TKey, TBase, TUp>(IDictionary<TKey, TBase>)

Upcasts the given IDictionary<TKey, TValue> into a dictionary whose values are TUp.

public static IDictionary<TKey, TUp> UpcastDictionary<TKey, TBase, TUp>(this IDictionary<TKey, TBase> source) where TKey : notnull where TUp : class, TBase

Parameters

source IDictionary<TKey, TBase>

Returns

IDictionary<TKey, TUp>

Type Parameters

TKey
TBase
TUp

Remarks

No validation is performed on whether all values are TUp. This method is unsafe and should be used on dictionaries where it is known.

UpcastList<TBase, TUp>(IList<TBase>)

Upcasts the given IList<T> into a list of TUp instances.

public static IList<TUp> UpcastList<TBase, TUp>(this IList<TBase> source) where TUp : class, TBase

Parameters

source IList<TBase>

The source list to upcast.

Returns

IList<TUp>

An instance that returns the source list's elements cast into TUp.

Type Parameters

TBase

The base type of the list's elements.

TUp

The type to upcast all of the list's elements.

Remarks

No validation is performed on whether all the elements of the list are TUp. This method is unsafe and should be used on lists where it is known. If an element is not actually TUp, accessing it (for example by indexing or enumeration) will throw an exception at runtime.

UpcastReadOnlyCollection<TBase, TUp>(IReadOnlyCollection<TBase>)

Upcasts the given IReadOnlyCollection<T> into a read-only collection of TUp instances.

public static IReadOnlyCollection<TUp> UpcastReadOnlyCollection<TBase, TUp>(this IReadOnlyCollection<TBase> source) where TUp : class, TBase

Parameters

source IReadOnlyCollection<TBase>

Returns

IReadOnlyCollection<TUp>

Type Parameters

TBase
TUp

Remarks

No validation is performed on whether all the elements are TUp. This method is unsafe and should be used on collections where it is known.

UpcastReadOnlyDictionary<TKey, TBase, TUp>(IReadOnlyDictionary<TKey, TBase>)

Upcasts the given IReadOnlyDictionary<TKey, TValue> into a read-only dictionary whose values are TUp.

public static IReadOnlyDictionary<TKey, TUp> UpcastReadOnlyDictionary<TKey, TBase, TUp>(this IReadOnlyDictionary<TKey, TBase> source) where TKey : notnull where TUp : class, TBase

Parameters

source IReadOnlyDictionary<TKey, TBase>

Returns

IReadOnlyDictionary<TKey, TUp>

Type Parameters

TKey
TBase
TUp

Remarks

No validation is performed on whether all values are TUp. This method is unsafe and should be used on dictionaries where it is known.

UpcastReadOnlyList<TBase, TUp>(IReadOnlyList<TBase>)

Upcasts the given IReadOnlyList<T> into a list of TUp instances.

public static IReadOnlyList<TUp> UpcastReadOnlyList<TBase, TUp>(this IReadOnlyList<TBase> source) where TUp : class, TBase

Parameters

source IReadOnlyList<TBase>

The source list to upcast.

Returns

IReadOnlyList<TUp>

An instance that returns the source list's elements cast into TUp.

Type Parameters

TBase

The base type of the list's elements.

TUp

The type to upcast all of the list's elements.

Remarks

No validation is performed on whether all the elements of the list are TUp. This method is unsafe and should be used on lists where it is known. If an element is not actually TUp, accessing it (for example by indexing or enumeration) will throw an exception at runtime.

UpcastReadOnlySet<TBase, TUp>(IReadOnlySet<TBase>)

Upcasts the given IReadOnlySet<T> into a read-only set of TUp instances.

public static IReadOnlySet<TUp> UpcastReadOnlySet<TBase, TUp>(this IReadOnlySet<TBase> source) where TUp : class, TBase

Parameters

source IReadOnlySet<TBase>

Returns

IReadOnlySet<TUp>

Type Parameters

TBase
TUp

Remarks

No validation is performed on whether all elements are TUp. This method is unsafe and should be used on sets where it is known.

UpcastSet<TBase, TUp>(ISet<TBase>)

Upcasts the given ISet<T> into a set of TUp instances.

public static ISet<TUp> UpcastSet<TBase, TUp>(this ISet<TBase> source) where TUp : class, TBase

Parameters

source ISet<TBase>

Returns

ISet<TUp>

Type Parameters

TBase
TUp

Remarks

No validation is performed on whether all elements are TUp. This method is unsafe and should be used on sets where it is known.