DynamicObject.TryCreateInstance Method

Definition

Provides the implementation for operations that initialize a new instance of a dynamic object. This method is not intended for use in C# or Visual Basic.

C#
public virtual bool TryCreateInstance(System.Dynamic.CreateInstanceBinder binder, object[] args, out object result);
C#
public virtual bool TryCreateInstance(System.Dynamic.CreateInstanceBinder binder, object?[]? args, out object? result);

Parameters

binder
CreateInstanceBinder

Provides information about the initialization operation.

args
Object[]

The arguments that are passed to the object during initialization. For example, for the new SampleType(100) operation, where SampleType is the type derived from the DynamicObject class, args[0] is equal to 100.

result
Object

The result of the initialization.

Returns

true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.)

Remarks

Classes derived from the DynamicObject class can override this method to specify how a new instance of the dynamic object should be initialized. When the method is not overridden, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.)

C# and Visual Basic compilers never emit code to use this method because they do not support first-class types. This method is intended for languages that support the initialization of dynamic objects by using syntax like dynamic new.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0