ReflectorCreateInstance(Type, Type, Object) Method

Creates a new instance of the specified type.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static Object CreateInstance(
	Type type,
	Type[]? genericParameters,
	params Object?[]? parameters
)

Parameters

type  Type
The Type of the instance to create.
genericParameters  Type
Type parameters if type refers to a generic type definition. Otherwise, this parameter is ignored.
parameters  Object
The parameters to be used for invoking the constructor.

Return Value

Object
The created instance of type.

Remarks

If you are not sure whether the type can be created by the provided genericParameters and parameters, then you can use the TryCreateInstance methods instead.

For creating the instance this method uses the DynamicDelegate way, unless for value types with empty or  parameters, in which case the SystemReflection way is selected, which will use the Activator class.

See Also