1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Microsoft Public License. A
6 * copy of the license can be found in the License.html file at the root of this distribution. If
7 * you cannot locate the Microsoft Public License, please send an email to
8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9 * by the terms of the Microsoft Public License.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
16 using System.Dynamic.Utils;
18 namespace System.Dynamic {
21 /// Represents the dynamic get index operation at the call site, providing the binding semantic and the details about the operation.
23 public abstract class GetIndexBinder : DynamicMetaObjectBinder {
24 private readonly CallInfo _callInfo;
27 /// Initializes a new instance of the <see cref="GetIndexBinder" />.
29 /// <param name="callInfo">The signature of the arguments at the call site.</param>
30 protected GetIndexBinder(CallInfo callInfo) {
31 ContractUtils.RequiresNotNull(callInfo, "callInfo");
36 /// The result type of the operation.
38 public override sealed Type ReturnType {
39 get { return typeof(object); }
43 /// Gets the signature of the arguments at the call site.
45 public CallInfo CallInfo {
46 get { return _callInfo; }
50 /// Performs the binding of the dynamic get index operation.
52 /// <param name="target">The target of the dynamic get index operation.</param>
53 /// <param name="args">An array of arguments of the dynamic get index operation.</param>
54 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
55 public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
56 ContractUtils.RequiresNotNull(target, "target");
57 ContractUtils.RequiresNotNullItems(args, "args");
59 return target.BindGetIndex(this, args);
62 // this is a standard DynamicMetaObjectBinder
63 internal override sealed bool IsStandardBinder {
70 /// Performs the binding of the dynamic get index operation if the target dynamic object cannot bind.
72 /// <param name="target">The target of the dynamic get index operation.</param>
73 /// <param name="indexes">The arguments of the dynamic get index operation.</param>
74 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
75 public DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes) {
76 return FallbackGetIndex(target, indexes, null);
80 /// When overridden in the derived class, performs the binding of the dynamic get index operation if the target dynamic object cannot bind.
82 /// <param name="target">The target of the dynamic get index operation.</param>
83 /// <param name="indexes">The arguments of the dynamic get index operation.</param>
84 /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
85 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
86 public abstract DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion);