TypeDescriptor.CreateInstance(IServiceProvider, Type, Type[], Object[]) 方法

定义

创建可替换为另一种数据类型的对象。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);
[<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

参数

provider
IServiceProvider

提供 TypeDescriptionProvider 服务的服务提供程序。The service provider that provides a TypeDescriptionProvider service. 此参数可以为 nullThis parameter can be null.

objectType
Type

要创建的对象的 TypeThe Type of object to create.

argTypes
Type[]

要传递给对象的构造函数的可选参数类型数组。An optional array of parameter types to be passed to the object's constructor. 此参数可以是 null 或长度为零的数组。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. 如果不是 null,元素数则必须与 argTypes 相同。If not null, the number of elements must be the same as argTypes.

返回

Object

如果找到关联的 TypeDescriptionProvider,则为替代数据类型的实例;否则为 nullAn instance of the substitute data type if an associated TypeDescriptionProvider is found; otherwise, null.

属性

例外

objectTypenull,或者,当 argTypes 不是 null 时,则 argsnullobjectType is null, or args is null when argTypes is not null.

argTypesargs 具有不同的元素数。argTypes and args have different number of elements.

注解

CreateInstance方法将搜索 TypeDescriptionProvider 与指定的数据类型相关联的 objectTypeThe CreateInstance method will search for a TypeDescriptionProvider that is associated with the specified objectType data type. 此方法首先尝试从参数获取类型说明提供程序 providerThis method first tries to obtain a type description provider from the provider parameter. 如果此操作失败,则它会在其自己的内部表中搜索提供程序, (这些项是通过先前对) 的调用创建的 AddProviderIf 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.

继承者说明

如果派生类未提供替换实例,则此方法应调用基实现。If the derived class does not provide a substitute instance, this method should call the base implementation.

适用于

另请参阅