Click or drag to resize
AlgorithmsTypedAsT Method (IEnumerable)
Given a non-generic IEnumerable interface, wrap a generic IEnumerable<T> interface around it. The generic interface will enumerate the same objects as the underlying non-generic collection, but can be used in places that require a generic interface. The underlying non-generic collection must contain only items that are of type T or a type derived from it. This method is useful when interfacing older, non-generic collections to newer code that uses generic interfaces.

Namespace: X3Platform.Collections
Assembly: X3Platform.Support (in X3Platform.Support.dll) Version: 1.0.0.0 (2.0.0.0)
Syntax
public static IEnumerable<T> TypedAs<T>(
	IEnumerable untypedCollection
)

Parameters

untypedCollection
Type: System.CollectionsIEnumerable
An untyped collection. This collection should only contain items of type T or a type derived from it.

Type Parameters

T
The item type of the wrapper collection.

Return Value

Type: IEnumerableT
A generic IEnumerable<T> wrapper around untypedCollection. If untypedCollection is null, then null is returned.
Remarks
Some collections implement both generic and non-generic interfaces. For efficiency, this method will first attempt to cast untypedCollection to IEnumerable<T>. If that succeeds, it is returned; otherwise, a wrapper object is created.
See Also