Redigera

Dela via


TypeDescriptor.CreateInstance Method

Definition

Creates an object that can substitute for another data type.

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

Parameters

provider
IServiceProvider

The service provider that provides a TypeDescriptionProvider service. This parameter can be null.

objectType
Type

The Type of object to create.

argTypes
Type[]

An optional array of parameter types to be passed to the object's constructor. This parameter can be null or an array of zero length.

args
Object[]

An optional array of parameter values to pass to the object's constructor. If not null, the number of elements must be the same as argTypes.

Returns

An instance of the substitute data type if an associated TypeDescriptionProvider is found; otherwise, null.

Attributes

Exceptions

objectType is null, or args is null when argTypes is not null.

argTypes and args have different number of elements.

Remarks

The CreateInstance method will search for a TypeDescriptionProvider that is associated with the specified objectType data type. This method first tries to obtain a type description provider from the provider parameter. If this fails, it searches its own internal tables for a provider (these entries were created through previous calls to AddProvider). If it finds a provider, this method will delegate the creation call to that object.

Notes to Inheritors

If the derived class does not provide a substitute instance, this method should call the base implementation.

Applies to

See also