Wintellect.PowerCollections Namespace
Algorithms Class
Algorithms Methods
GhostDoc Pro Sample Help File

Algorithms..::..TypedAs<(Of <(<'T>)>)> Method (ICollection)

Given a non-generic ICollection interface, wrap a generic ICollection<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:  Wintellect.PowerCollections
Assembly:  PowerCollections (in PowerCollections.dll)

Syntax


public static ICollection<T> TypedAs<T>(
	ICollection untypedCollection
)
Public Shared Function TypedAs(Of T) ( _
	untypedCollection As ICollection _
) As ICollection(Of T)
public:
generic<typename T>
static ICollection<T>^ TypedAs(
	ICollection^ untypedCollection
)

Type Parameters

T
The item type of the wrapper collection.

Parameters

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

Return Value

A generic ICollection<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 ICollection<T>. If that succeeds, it is returned; otherwise, a wrapper object is created.

Unlike the generic interface, the non-generic ICollection interfaces does not contain methods for adding or removing items from the collection. For this reason, the returned ICollection<T> will be read-only.