Bewerken

Delen via


DesignerSerializationManager.CreateInstance Method

Definition

Creates an instance of a type.

protected:
 virtual System::Object ^ CreateInstance(Type ^ type, System::Collections::ICollection ^ arguments, System::String ^ name, bool addToContainer);
protected virtual object CreateInstance (Type type, System.Collections.ICollection arguments, string name, bool addToContainer);
protected virtual object CreateInstance (Type type, System.Collections.ICollection? arguments, string? name, bool addToContainer);
abstract member CreateInstance : Type * System.Collections.ICollection * string * bool -> obj
override this.CreateInstance : Type * System.Collections.ICollection * string * bool -> obj
Protected Overridable Function CreateInstance (type As Type, arguments As ICollection, name As String, addToContainer As Boolean) As Object

Parameters

type
Type

The type to create an instance of.

arguments
ICollection

The parameters of the type's constructor. This can be null or an empty collection to invoke the parameterless constructor.

name
String

A name to give the object. If null, the object will not be given a name, unless the object is added to a container and the container gives the object a name.

addToContainer
Boolean

true to add the object to the container if the object implements IComponent; otherwise, false.

Returns

A new instance of the type specified by type.

Exceptions

type does not have a constructor that takes parameters contained in arguments.

Remarks

This method is called by serializers when they attempt to create an instance of a type. The default implementation creates a new instance of the type, or it may return an existing instance depending on the values of the PreserveNames and RecycleInstances properties. The CreateInstance method uses reflection to create instances and will perform some generic IConvertible transformations on parameters to find a matching constructor.

Applies to

See also