System.Dynamic.DynamicObject.TrySetMember Method

Provides the implementation for operations that set member values. Classes derived from the System.Dynamic.DynamicObject class can override this method to specify dynamic behavior for operations such as setting a value for a property.

Syntax

public virtual bool TrySetMember (SetMemberBinder binder, object value)

Parameters

binder
Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member to which the value is being assigned. For example, for the statement sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the System.Dynamic.DynamicObject class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.
value
The value to set to the member. For example, for sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the System.Dynamic.DynamicObject class, the value is "Test".

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 System.Dynamic.DynamicObject class can override this method to specify how operations that set a value to a member should be performed for a dynamic object. 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.)

This method is called when you have statements like sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class that is derived from the System.Dynamic.DynamicObject class.

You can also add your own members to classes derived from the DynamicObject class. If your class defines properties and also overrides the DynamicObject.TrySetMember(SetMemberBinder, object) method, the dynamic language runtime (DLR) first uses the language binder to look for a static definition of a property in the class. If there is no such property, the DLR calls the DynamicObject.TrySetMember(SetMemberBinder, object) method.

Requirements

Namespace: System.Dynamic
Assembly: System.Core (in System.Core.dll)
Assembly Versions: 4.0.0.0