ReflectorTryCreateInstance(Type, Type, ReflectionWays, 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,
	Type[]? genericParameters,
	ReflectionWays way,
	out Object?? result
)

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
The preferred reflection way.
result  Object
When this method returns with result, then this parameter contains the created instance of type.

Return Value

Boolean
, if the instance could be created; , if type cannot be created without parameters or genericParameters do not match to the generic type definition.

Remarks

  Note

If an instance can be created by its parameterless constructor 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.

See Also