ReflectorCreateInstance(Type, ReflectionWays, 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,
	ReflectionWays way,
	params Object?[]? parameters
)

Parameters

type  Type
The Type of the instance to create.
way  ReflectionWays
The preferred reflection way.
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 parameters, then you can use the TryCreateInstance methods instead.

If way is Auto, then 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