System.Core
4.0.0.0
System.Object
System.Dynamic.IDynamicMetaObjectProvider
The DynamicObject class enables you to define which operations can be performed on dynamic objects and how to perform those operations. For example, you can define what happens when you try to get or set an object property, call a method, or perform standard mathematical operations such as addition and multiplication.
This class can be useful if you want to create a more convenient protocol for a library. For example, if users of your library have to use syntax like Scriptobj.SetProperty("Count", 1), you can provide the ability to use much simpler syntax, like scriptobj.Count = 1.
You cannot directly create an instance of the DynamicObject class. To implement the dynamic behavior, you may want to inherit from the DynamicObject class and override necessary methods. For example, if you need only operations for setting and getting properties, you can override just the and methods.
In C#, to enable dynamic behavior for instances of classes derived from the DynamicObject class, you must use the dynamic keyword. For more information, see Using Type Dynamic (C# Programming Guide).
In Visual Basic, dynamic operations are supported by late binding. For more information, see Early and Late Binding.
The following code example demonstrates how to create an instance of a class that is derived from the DynamicObject class.
public class SampleDynamicObject : DynamicObject {}
//...
dynamic sampleObject = new SampleDynamicObject ();
Public Class SampleDynamicObject
Inherits DynamicObject
'...
Dim sampleObject As Object = New SampleDynamicObject()
You can also add your own members to classes derived from the DynamicObject class. If your class defines properties and also overrides the 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 method.
The DynamicObject class implements the DLR interface , which enables you to share instances of the DynamicObject class between languages that support the DLR interoperability model. For example, you can create an instance of the DynamicObject class in C# and then pass it to an IronPython function. For more information, see Dynamic Language Runtime Overview and documentation on the CodePlex Web site.
If you have a simple scenario in which you need an object that can only add and remove members at run time but that does not need to define specific operations and does not have static members, use the class.
If you have a more advanced scenario in which you need to define how dynamic objects participate in the interoperability protocol, or you need to manage DLR fast dynamic dispatch caching, create your own implementation of the interface.
Provides a base class for specifying dynamic behavior at run time. This class must be inherited from; you cannot instantiate it directly.
Constructor
4.0.0.0
You cannot directly create an instance of the class. To implement dynamic behavior, you have to inherit from the class and override necessary methods.
In C#, to enable dynamic behavior for instances of the classes derived from the class, you must use the dynamic keyword. For more information, see Using Type Dynamic (C# Programming Guide).
In Visual Basic, dynamic operations are supported by late binding. For more information, see Early and Late Binding.
Enables derived types to initialize a new instance of the type.
Method
4.0.0.0
System.Collections.Generic.IEnumerable<System.String>
This method exists for debugging purposes only.
Returns the enumeration of all dynamic member names.
A sequence that contains dynamic member names.
Method
4.0.0.0
System.Dynamic.DynamicMetaObject
To be added.
Provides a that dispatches to the dynamic virtual methods. The object can be encapsulated inside another to provide custom behavior for individual actions. This method supports the Dynamic Language Runtime infrastructure for language implementers and it is not intended to be used directly from your code.
An object of the type.
The expression that represents to dispatch to the dynamic virtual methods.
Method
4.0.0.0
System.Boolean
To be added.
To be added.
To be added.
To be added.
To be added.
To be added.
Method
4.0.0.0
System.Boolean
To be added.
To be added.
To be added.
To be added.
To be added.
Method
4.0.0.0
System.Boolean
To be added.
To be added.
To be added.
To be added.
To be added.
To be added.
Method
4.0.0.0
System.Boolean
Classes derived from the class can override this method to specify how a value that has a specified index should be deleted. 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 this kind of operation. This method is intended for languages that support syntax for deleting objects by index, such as del sampleObject[1,2] in Python.
Provides the implementation for operations that delete an object by index. This method is not intended for use in C# or Visual Basic.
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.)
Provides information about the deletion.
The indexes to be deleted.
Method
4.0.0.0
System.Boolean
Classes derived from the class can override this method to specify how an object member should be deleted. When this 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 this kind of operation. This method is intended for languages that support syntax for deleting members, such as del sampleObject.SampleMember in Python.
Provides the implementation for operations that delete an object member. This method is not intended for use in C# or Visual Basic.
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.)
Provides information about the deletion.
Method
4.0.0.0
System.Boolean
To be added.
To be added.
To be added.
To be added.
To be added.
To be added.
Method
4.0.0.0
System.Boolean
To be added.
To be added.
To be added.
To be added.
To be added.
Method
4.0.0.0
System.Boolean
To be added.
To be added.
To be added.
To be added.
To be added.
To be added.
Method
4.0.0.0
System.Boolean
To be added.
To be added.
To be added.
To be added.
To be added.
To be added.
Method
4.0.0.0
System.Boolean
Classes derived from the class can override this method to specify how operations that access an object by index 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.)
If this method is overridden, it is automatically invoked when you have an operation like sampleObject[3] = 10 in C# or sampleObject(3) = 10 in Visual Basic, where sampleObject is derived from the class.
Provides the implementation for operations that set a value by index. Classes derived from the class can override this method to specify dynamic behavior for operations that access objects by a specified index.
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.
Provides information about the operation.
The indexes that are used in the operation. For example, for the sampleObject[3] = 10 operation in C# (sampleObject(3) = 10 in Visual Basic), where sampleObject is derived from the class, is equal to 3.
The value to set to the object that has the specified index. For example, for the sampleObject[3] = 10 operation in C# (sampleObject(3) = 10 in Visual Basic), where sampleObject is derived from the class, is equal to 10.
Method
4.0.0.0
System.Boolean
Classes derived from the 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 class.
You can also add your own members to classes derived from the DynamicObject class. If your class defines properties and also overrides the 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 method.
Provides the implementation for operations that set member values. Classes derived from the class can override this method to specify dynamic behavior for operations such as setting a value for a property.
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.)
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 class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.
The value to set to the member. For example, for sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the class, the is "Test".
Method
4.0.0.0
System.Boolean
To be added.
To be added.
To be added.
To be added.
To be added.