ExportProvider.GetExportedValueOrDefault ExportProvider.GetExportedValueOrDefault ExportProvider.GetExportedValueOrDefault ExportProvider.GetExportedValueOrDefault Method

定義

取得指定匯出物件或預設值 (如果有的話)。Gets a specified exported object or a default value if it is unavailable.

多載

GetExportedValueOrDefault<T>() GetExportedValueOrDefault<T>() GetExportedValueOrDefault<T>() GetExportedValueOrDefault<T>()

取得具有從指定型別參數或指定型別的預設值衍生之合約名稱的匯出物件,或者如果有一個以上相符的匯出物件,則擲回例外狀況。Gets the exported object with the contract name derived from the specified type parameter or the default value for the specified type, or throws an exception if there is more than one matching exported object.

GetExportedValueOrDefault<T>(String) GetExportedValueOrDefault<T>(String) GetExportedValueOrDefault<T>(String) GetExportedValueOrDefault<T>(String)

取得具有指定合約名稱或指定型別預設值的匯出物件,或者如果有一個以上相符的匯出物件,則擲回例外狀況。Gets the exported object with the specified contract name or the default value for the specified type, or throws an exception if there is more than one matching exported object.

GetExportedValueOrDefault<T>() GetExportedValueOrDefault<T>() GetExportedValueOrDefault<T>() GetExportedValueOrDefault<T>()

取得具有從指定型別參數或指定型別的預設值衍生之合約名稱的匯出物件,或者如果有一個以上相符的匯出物件,則擲回例外狀況。Gets the exported object with the contract name derived from the specified type parameter or the default value for the specified type, or throws an exception if there is more than one matching exported object.

public:
generic <typename T>
 T GetExportedValueOrDefault();
public T GetExportedValueOrDefault<T> ();
member this.GetExportedValueOrDefault : unit -> 'T
Public Function GetExportedValueOrDefault(Of T) () As T

類型參數

T

要傳回之已匯出的物件型別。The type of the exported object to return. 合約名稱也是從這個型別參數衍生。The contract name is also derived from this type parameter.

傳回

T T T T

具有從 T 衍生之合約名稱的匯出物件 (如果找到的話),否則,為預設值 TThe exported object with the contract name derived from T, if found; otherwise, the default value for T.

例外狀況

有一個以上具有合約名稱的匯出物件衍生自 CompositionContainer 中的 TThere is more than one exported object with the contract name derived from T in the CompositionContainer.

基礎的匯出物件無法轉換成 TThe underlying exported object cannot be cast to T.

在撰寫期間發生錯誤。An error occurred during composition. Errors 將包含發生之錯誤的集合。Errors will contain a collection of errors that occurred.

備註

如果找不到匯出的物件,這個方法會傳回適當的預設值T; 例如,整數類型零false布林類型,以及null參考型別。If the exported object is not found, this method returns the appropriate default value for T; for example, zero for integer types, false for Boolean types, and null for reference types.

合約名稱是呼叫GetContractName方法TThe contract name is the result of calling the GetContractName method on T.

合約名稱會比較使用Ordinal執行區分大小寫、 非語言比較的屬性。The contract name is compared by using the Ordinal property to perform a case-sensitive, non-linguistic comparison.

GetExportedValueOrDefault<T>(String) GetExportedValueOrDefault<T>(String) GetExportedValueOrDefault<T>(String) GetExportedValueOrDefault<T>(String)

取得具有指定合約名稱或指定型別預設值的匯出物件,或者如果有一個以上相符的匯出物件,則擲回例外狀況。Gets the exported object with the specified contract name or the default value for the specified type, or throws an exception if there is more than one matching exported object.

public:
generic <typename T>
 T GetExportedValueOrDefault(System::String ^ contractName);
public T GetExportedValueOrDefault<T> (string contractName);
member this.GetExportedValueOrDefault : string -> 'T
Public Function GetExportedValueOrDefault(Of T) (contractName As String) As T

類型參數

T

要傳回之已匯出的物件型別。The type of the exported object to return.

參數

contractName
String String String String

要傳回的匯出物件的合約名稱,或者是 null,或者是要使用預設合約名稱的空字串 ("")。The contract name of the exported object to return, or null or an empty string ("") to use the default contract name.

傳回

T T T T

具有指定合約名稱的匯出物件 (如果找到的話),否則,為預設值 TThe exported object with the specified contract name, if found; otherwise, the default value for T.

例外狀況

CompositionContainer 中有一個以上具有指定之合約名稱的匯出物件。There is more than one exported object with the specified contract name in the CompositionContainer.

基礎的匯出物件無法轉換成 TThe underlying exported object cannot be cast to T.

在撰寫期間發生錯誤。An error occurred during composition. Errors 將包含發生之錯誤的集合。Errors will contain a collection of errors that occurred.

備註

如果找不到匯出的物件,這個方法會傳回適當的預設值T; 例如,整數類型零false布林類型,以及null參考型別。If the exported object is not found, this method returns the appropriate default value for T; for example, zero for integer types, false for Boolean types, and null for reference types.

預設合約名稱是呼叫GetContractName方法TThe default contract name is the result of calling the GetContractName method on T.

合約名稱會比較使用Ordinal執行區分大小寫、 非語言比較的屬性。The contract name is compared by using the Ordinal property to perform a case-sensitive, non-linguistic comparison.

適用於