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
sourceICollection<TBase>
Returns
- ICollection<TUp>
Type Parameters
TBaseTUp
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
sourceIDictionary<TKey, TBase>
Returns
- IDictionary<TKey, TUp>
Type Parameters
TKeyTBaseTUp
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
sourceIList<TBase>The source list to upcast.
Returns
- IList<TUp>
An instance that returns the source list's elements cast into
TUp.
Type Parameters
TBaseThe base type of the list's elements.
TUpThe 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
sourceIReadOnlyCollection<TBase>
Returns
- IReadOnlyCollection<TUp>
Type Parameters
TBaseTUp
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
sourceIReadOnlyDictionary<TKey, TBase>
Returns
- IReadOnlyDictionary<TKey, TUp>
Type Parameters
TKeyTBaseTUp
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
sourceIReadOnlyList<TBase>The source list to upcast.
Returns
- IReadOnlyList<TUp>
An instance that returns the source list's elements cast into
TUp.
Type Parameters
TBaseThe base type of the list's elements.
TUpThe 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
sourceIReadOnlySet<TBase>
Returns
- IReadOnlySet<TUp>
Type Parameters
TBaseTUp
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
sourceISet<TBase>
Returns
- ISet<TUp>
Type Parameters
TBaseTUp
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.