TypeDescriptionProvider.CreateInstance 方法

定義

建立可以代替另一種資料類型的物件。

public:
 virtual System::Object ^ CreateInstance(IServiceProvider ^ provider, Type ^ objectType, cli::array <Type ^> ^ argTypes, cli::array <System::Object ^> ^ args);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public virtual object CreateInstance (IServiceProvider provider, Type objectType, Type[] argTypes, object[] args);
public virtual object? CreateInstance (IServiceProvider? provider, Type objectType, Type[]? argTypes, object[]? args);
public virtual object? CreateInstance (IServiceProvider? provider, Type objectType, Type[]? argTypes, object?[]? args);
public virtual object CreateInstance (IServiceProvider provider, Type objectType, Type[] argTypes, object[] args);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
abstract member CreateInstance : IServiceProvider * Type * Type[] * obj[] -> obj
override this.CreateInstance : IServiceProvider * Type * Type[] * obj[] -> obj
abstract member CreateInstance : IServiceProvider * Type * Type[] * obj[] -> obj
override this.CreateInstance : IServiceProvider * Type * Type[] * obj[] -> obj
Public Overridable Function CreateInstance (provider As IServiceProvider, objectType As Type, argTypes As Type(), args As Object()) As Object

參數

provider
IServiceProvider

選擇性的服務提供者。

objectType
Type

要建立之物件的類型。 這個參數絕對不是 null

argTypes
Type[]

選擇性的型別陣列,表示要傳遞至物件建構函式的參數型別。 這個陣列可以是 null 或長度為零。

args
Object[]

要傳遞給物件建構函式的選擇性參數值陣列。

傳回

替代的 Object

屬性

備註

由參數指定的 providerIServiceProviderTypeDescriptor.CreateInstance 類別的 TypeDescriptor 方法傳入。 如果 provider 不是 null,則型別描述提供者可以使用服務提供者來取得建立呼叫的其他內容。

方法CreateInstance預設為 ,如果 parentvirtualnull,則會傳回方法的結果Activator.CreateInstance。 如果 parent 不是 null,這個方法會叫 CreateInstance 用父提供者的 方法。

給繼承者的注意事項

如果衍生類別對提供替代實例不感興趣,它應該只會呼叫基底實作。

適用於

另請參閱