ReflectorCreateInstance(Type, Type, ReflectionWays) 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,
	ReflectionWays way = ReflectionWays.Auto
)

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.
way  ReflectionWays  (Optional)
The preferred reflection way. This parameter is optional.
Default value: Auto.

Return Value

Object
The created instance of type.

Remarks

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

If way is Auto, then this method uses the DynamicDelegate way.

See Also