Edit

Share via


CollectionAdapters.ToIList Method

Definition

Overloads

ToIList<T>(IListContract<T>)

Converts the specified IListContract<T> collection to an IList<T> collection.

ToIList<TContract,TView>(IListContract<TContract>, Converter<TContract,TView>, Converter<TView,TContract>)

Converts a specified IListContract<T> collection to an IList<T> collection by using converter adapters.

ToIList<T>(IListContract<T>)

Converts the specified IListContract<T> collection to an IList<T> collection.

public:
generic <typename T>
 static System::Collections::Generic::IList<T> ^ ToIList(System::AddIn::Contract::IListContract<T> ^ collection);
public static System.Collections.Generic.IList<T> ToIList<T> (System.AddIn.Contract.IListContract<T> collection);
static member ToIList : System.AddIn.Contract.IListContract<'T> -> System.Collections.Generic.IList<'T>
Public Shared Function ToIList(Of T) (collection As IListContract(Of T)) As IList(Of T)

Type Parameters

T

The type of objects that are contained in the list. T must be serializable.

Parameters

collection
IListContract<T>

The collection from the other side of the pipeline.

Returns

The converted collection.

Examples

The following example implements a host-side adapter pipeline segment as described Walkthrough: Passing Collections Between Hosts and Add-Ins. The example adapts the custom ProcessBooks method by taking the IListContract<T> collection passed from the add-in and converting it to an IList<T> collection, which the host application can then use.

public virtual void ProcessBooks(IListContract<Library.IBookInfoContract> books)
{
    _view.ProcessBooks(CollectionAdapters.ToIList<Library.IBookInfoContract,
        LibraryContractsBase.BookInfo>(books,
        LibraryContractsAddInAdapters.BookInfoAddInAdapter.ContractToViewAdapter,
        LibraryContractsAddInAdapters.BookInfoAddInAdapter.ViewToContractAdapter));
}
Public Overridable Sub ProcessBooks(ByVal books As IListContract(Of Library.IBookInfoContract)) Implements Library.ILibraryManagerContract.ProcessBooks
    _view.ProcessBooks(CollectionAdapters.ToIList(Of Library.IBookInfoContract, _
    LibraryContractsBase.BookInfo)(books, _
    AddressOf LibraryContractsAddInAdapters.BookInfoAddInAdapter.ContractToViewAdapter, _
    AddressOf LibraryContractsAddInAdapters.BookInfoAddInAdapter.ViewToContractAdapter))
End Sub

Remarks

The host application or add-in can use the returned IList<T> collection. The IList<T> collection will have a lifetime token for the remote IListContract<T> collection.

You should use this method overload only when the contents of the IListContract<T> are serializable types that can be passed directly to the add-in and host (rather than types that must be adapted into views).

Applies to

ToIList<TContract,TView>(IListContract<TContract>, Converter<TContract,TView>, Converter<TView,TContract>)

Converts a specified IListContract<T> collection to an IList<T> collection by using converter adapters.

public:
generic <typename TContract, typename TView>
 static System::Collections::Generic::IList<TView> ^ ToIList(System::AddIn::Contract::IListContract<TContract> ^ collection, Converter<TContract, TView> ^ contractViewAdapter, Converter<TView, TContract> ^ viewContractAdapter);
public static System.Collections.Generic.IList<TView> ToIList<TContract,TView> (System.AddIn.Contract.IListContract<TContract> collection, Converter<TContract,TView> contractViewAdapter, Converter<TView,TContract> viewContractAdapter);
static member ToIList : System.AddIn.Contract.IListContract<'Contract> * Converter<'Contract, 'View> * Converter<'View, 'Contract> -> System.Collections.Generic.IList<'View>
Public Shared Function ToIList(Of TContract, TView) (collection As IListContract(Of TContract), contractViewAdapter As Converter(Of TContract, TView), viewContractAdapter As Converter(Of TView, TContract)) As IList(Of TView)

Type Parameters

TContract

The type that defines the contract for passing objects of type TView across the isolation boundary.

TView

The type that defines the view of the objects in the list.

Parameters

collection
IListContract<TContract>

The collection to pass to the other side of the pipeline.

contractViewAdapter
Converter<TContract,TView>

A converter that adapts the data from the type defined in the contract to the type expected in the view.

viewContractAdapter
Converter<TView,TContract>

A converter that adapts the data from the type defined in the view to the type expected by the contract.

Returns

IList<TView>

The converted collection.

Remarks

Use this method overload for IListContract<T> collections that contain types that must be adapted before they can be passed to the add-in or host (rather than simple serializable types that can be passed directly). The host application or add-in can use the returned IList<T> collection. It will have a lifetime token for the remote IListContract<T>.

Applies to