Provides the implementation for operations that get a value by index. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for indexing operations.
Assemblies: System.Dynamic.Runtime (in System.Dynamic.Runtime.dll)
System.Core (in System.Core.dll)
abstract TryGetIndex : binder:GetIndexBinder * indexes:Object * result:Object byref -> bool override TryGetIndex : binder:GetIndexBinder * indexes:Object * result:Object byref -> bool
- Type: System.Dynamic.GetIndexBinder
Provides information about the operation.
- Type: System.Object
The indexes that are used in the operation. For example, for the sampleObject operation in C# (sampleObject(3) in Visual Basic), where sampleObject is derived from the DynamicObject class, indexes is equal to 3.
- Type: System.Object
The result of the index operation.
Return ValueType: System.Boolean
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 run-time exception is thrown.)
Classes derived from the DynamicObject class can override this method to specify how getting a value 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 run-time exception is thrown.)
If this method is overridden, it is automatically invoked when you have an operation like sampleObject in C# or sampleObject(3) in Visual Basic, where sampleObject is derived from the DynamicObject class.
Assume that you want to create an object in which properties can be accessed either by names such as Property0, Property1, and so on, or by index, so that, for example, sampleObject.Property0 is equivalent to sampleObject in C# or sampleObject(0) in Visual Basic.
The following code example demonstrates the SampleDynamicObject class, which is derived from the DynamicObject class. The SampleDynamicObject class contains an object of the Dictionary<string, object> type (Dictionary(Of String, Object) in Visual Basic) to store the key-value pairs. SampleDynamicObject overrides the TrySetIndex and methods to enable access by index. It overrides the TrySetMember and TryGetMember methods to enable access by property name.