Edit

Share via


CollectionAdapters.ToIListContract Method

Definition

Overloads

ToIListContract<T>(IList<T>)

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

ToIListContract<TView,TContract>(IList<TView>, Converter<TView,TContract>, Converter<TContract,TView>)

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

ToIListContract<T>(IList<T>)

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

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

Type Parameters

T

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

Parameters

collection
IList<T>

The collection to convert.

Returns

The converted collection.

Examples

The following example implements the class that defines an add-in side adapter pipeline segment. It adapts the custom ProcessBooks method by taking the IList<T> collection passed from the add-in view segment and converting it to an IListContract<T> collection that can be marshaled across the isolation boundary to the host.

public override void ProcessBooks(IList<LibraryContractsHAV.BookInfo> books) {
    _contract.ProcessBooks(CollectionAdapters.ToIListContract<LibraryContractsHAV.BookInfo,
        Library.IBookInfoContract>(books,
        LibraryContractsHostAdapters.BookInfoHostAdapter.ViewToContractAdapter,
        LibraryContractsHostAdapters.BookInfoHostAdapter.ContractToViewAdapter));
}
Public Overrides Sub ProcessBooks(ByVal books As IList(Of LibraryContractsHAV.BookInfo))
    _contract.ProcessBooks(CollectionAdapters.ToIListContract(Of LibraryContractsHAV.BookInfo, _
    Library.IBookInfoContract)(books, _
    AddressOf LibraryContractsHostAdapters.BookInfoHostAdapter.ViewToContractAdapter, _
    AddressOf LibraryContractsHostAdapters.BookInfoHostAdapter.ContractToViewAdapter))
End Sub

Remarks

The IListContract<T> collection can be marshaled across the isolation boundary between the add-in and its host application.

You should use this method overload only when the contents of the IList<T> collection are serializable types that can be passed directly to the contract (rather than types that must be adapted into contracts).

Applies to

ToIListContract<TView,TContract>(IList<TView>, Converter<TView,TContract>, Converter<TContract,TView>)

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

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

Type Parameters

TView

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

TContract

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

Parameters

collection
IList<TView>

The collection to convert.

viewContractAdapter
Converter<TView,TContract>

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

contractViewAdapter
Converter<TContract,TView>

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

Returns

IListContract<TContract>

The converted collection.

Remarks

Use this method overload for IList<T> collections that contain types that must be adapted into contracts before they can be passed to the contract (rather than simple serializable types that can be passed directly). The IListContract<T> collection can be marshaled across the isolation boundary between an add-in and its host application.

Applies to