CollectionAdapters.ToIListContract 方法

定义

重载

ToIListContract<T>(IList<T>)

将指定的 IList<T> 集合转换为 IListContract<T> 集合。Converts a specified IList<T> collection to an IListContract<T> collection.

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

通过使用转换器适配器将指定的 IList<T> 集合转换为 IListContract<T> 集合。Converts a specified IList<T> collection to an IListContract<T> collection by using converter adapters.

ToIListContract<T>(IList<T>)

将指定的 IList<T> 集合转换为 IListContract<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)

类型参数

T

列表中所含对象的类型。The type of objects that are contained in the list. T 必须可序列化。T must be serializable.

参数

collection
IList<T>

要转换的集合。The collection to convert.

返回

IListContract<T>

已转换的集合。The converted collection.

示例

下面的示例实现定义外接程序端适配器管道段的类。The following example implements the class that defines an add-in side adapter pipeline segment. ProcessBooks 通过 IList<T> 从外接程序视图段获取集合并将其转换为 IListContract<T> 可在隔离边界之间跨隔离边界进行封送的集合,来改编自定义方法。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

注解

IListContract<T> 集合可以跨外接程序与其主机应用程序之间的隔离边界进行封送处理。The IListContract<T> collection can be marshaled across the isolation boundary between the add-in and its host application.

仅当集合的内容 IList<T> 是可直接传递给协定 (而不是必须改编到协定) 中的类型时,才应使用此方法重载。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).

适用于

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

通过使用转换器适配器将指定的 IList<T> 集合转换为 IListContract<T> 集合。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)

类型参数

TView

定义列表中各个对象的视图的类型。The type that defines the view of the objects in the list.

TContract

定义用于跨隔离边界传递 TView 类型对象的协定的类型。The type that defines the contract for passing objects of type TView across the isolation boundary.

参数

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.

返回

IListContract<TContract>

已转换的集合。The converted collection.

注解

对于 IList<T> 包含必须在协定中改编的类型的集合,请使用此方法重载,以便将这些类型传递给协定 (而不是可以直接传递) 的简单可序列化类型。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). IListContract<T>集合可跨外接程序与其主机应用程序之间的隔离边界进行封送处理。The IListContract<T> collection can be marshaled across the isolation boundary between an add-in and its host application.

适用于