ReflectorTryCreateInstance(Type, ReflectionWays, Object, Object) Method

Tries to create 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 bool TryCreateInstance(
	Type type,
	ReflectionWays way,
	out Object result,
	params Object?[]? parameters
)

Parameters

type  Type
The Type of the instance to create.
way  ReflectionWays
The preferred reflection way.
result  Object
When this method returns with result, then this parameter contains the created instance of type.
parameters  Object
The parameters to be used for invoking the constructor.

Return Value

Boolean
, if the instance could be created; , if type cannot be created by the provided parameters.

Remarks

  Note

If a matching constructor could be found and the constructor itself has thrown an exception, then this method also throws an exception instead of returning .

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