Επεξεργασία

Κοινή χρήση μέσω


ExportProvider.GetExportedValueOrDefault Method

Definition

Gets a specified exported object or a default value if it is unavailable.

Overloads

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)

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>()

Source:
ExportProvider.GetExportOverrides.cs
Source:
ExportProvider.GetExportOverrides.cs
Source:
ExportProvider.GetExportOverrides.cs

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> ();
public T GetExportedValueOrDefault<T> ();
member this.GetExportedValueOrDefault : unit -> 'T
Public Function GetExportedValueOrDefault(Of T) () As T

Type Parameters

T

The type of the exported object to return. The contract name is also derived from this type parameter.

Returns

T

The exported object with the contract name derived from T, if found; otherwise, the default value for T.

Exceptions

There is more than one exported object with the contract name derived from T in the CompositionContainer.

The CompositionContainer object has been disposed of.

The underlying exported object cannot be cast to T.

An error occurred during composition. Errors will contain a collection of errors that occurred.

Remarks

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.

The contract name is the result of calling the GetContractName method on T.

The contract name is compared by using the Ordinal property to perform a case-sensitive, non-linguistic comparison.

Applies to

GetExportedValueOrDefault<T>(String)

Source:
ExportProvider.GetExportOverrides.cs
Source:
ExportProvider.GetExportOverrides.cs
Source:
ExportProvider.GetExportOverrides.cs

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);
public T GetExportedValueOrDefault<T> (string contractName);
member this.GetExportedValueOrDefault : string -> 'T
Public Function GetExportedValueOrDefault(Of T) (contractName As String) As T

Type Parameters

T

The type of the exported object to return.

Parameters

contractName
String

The contract name of the exported object to return, or null or an empty string ("") to use the default contract name.

Returns

T

The exported object with the specified contract name, if found; otherwise, the default value for T.

Exceptions

There is more than one exported object with the specified contract name in the CompositionContainer.

The CompositionContainer object has been disposed of.

The underlying exported object cannot be cast to T.

An error occurred during composition. Errors will contain a collection of errors that occurred.

Remarks

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.

The default contract name is the result of calling the GetContractName method on T.

The contract name is compared by using the Ordinal property to perform a case-sensitive, non-linguistic comparison.

Applies to