.NET Framework Class Library
TypeDescriptor..::.CreateInstance Method

Creates an object that can substitute for another data type.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)
Syntax

Visual Basic (Declaration)
Public Shared Function CreateInstance ( _
    provider As IServiceProvider, _
    objectType As Type, _
    argTypes As Type(), _
    args As Object() _
) As Object
Visual Basic (Usage)
Dim provider As IServiceProvider
Dim objectType As Type
Dim argTypes As Type()
Dim args As Object()
Dim returnValue As Object

returnValue = TypeDescriptor.CreateInstance(provider, _
    objectType, argTypes, args)
C#
public static Object CreateInstance(
    IServiceProvider provider,
    Type objectType,
    Type[] argTypes,
    Object[] args
)
Visual C++
public:
static Object^ CreateInstance(
    IServiceProvider^ provider, 
    Type^ objectType, 
    array<Type^>^ argTypes, 
    array<Object^>^ args
)
JScript
public static function CreateInstance(
    provider : IServiceProvider, 
    objectType : Type, 
    argTypes : Type[], 
    args : Object[]
) : Object

Parameters

provider
Type: System..::.IServiceProvider
The service provider that provides a TypeDescriptionProvider service. This parameter can be nullNothingnullptra null reference (Nothing in Visual Basic).
objectType
Type: System..::.Type
The Type of object to create.
argTypes
Type: array<System..::.Type>[]()[]
An optional array of parameter types to be passed to the object's constructor. This parameter can be nullNothingnullptra null reference (Nothing in Visual Basic) or an array of zero length.
args
Type: array<System..::.Object>[]()[]
An optional array of parameter values to pass to the object's constructor. If not nullNothingnullptra null reference (Nothing in Visual Basic), the number of elements must be the same as argTypes.

Return Value

Type: System..::.Object
An instance of the substitute data type if an associated TypeDescriptionProvider is found; otherwise, nullNothingnullptra null reference (Nothing in Visual Basic).
Exceptions

ExceptionCondition
ArgumentNullException

objectType is nullNothingnullptra null reference (Nothing in Visual Basic), or args is nullNothingnullptra null reference (Nothing in Visual Basic) when argTypes is not nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentException

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.

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Tags :


Page view tracker