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 * ***************************************************************************/
15 using System; using Microsoft;
19 using System.Dynamic.Utils;
21 using Microsoft.Scripting.Utils;
25 namespace System.Dynamic {
27 namespace Microsoft.Scripting {
31 /// Represents the dynamic set index operation at the call site, providing the binding semantic and the details about the operation.
33 public abstract class SetIndexBinder : DynamicMetaObjectBinder {
34 private readonly CallInfo _callInfo;
37 /// Initializes a new instance of the <see cref="SetIndexBinder" />.
39 /// <param name="callInfo">The signature of the arguments at the call site.</param>
40 protected SetIndexBinder(CallInfo callInfo) {
41 ContractUtils.RequiresNotNull(callInfo, "callInfo");
46 /// The result type of the operation.
48 public override sealed Type ReturnType {
49 get { return typeof(object); }
53 /// Gets the signature of the arguments at the call site.
55 public CallInfo CallInfo {
56 get { return _callInfo; }
60 /// Performs the binding of the dynamic set index operation.
62 /// <param name="target">The target of the dynamic set index operation.</param>
63 /// <param name="args">An array of arguments of the dynamic set index operation.</param>
64 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
65 public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
66 ContractUtils.RequiresNotNull(target, "target");
67 ContractUtils.RequiresNotNull(args, "args");
68 ContractUtils.Requires(args.Length >= 2, "args");
70 DynamicMetaObject value = args[args.Length - 1];
71 DynamicMetaObject[] indexes = args.RemoveLast();
73 ContractUtils.RequiresNotNull(value, "args");
74 ContractUtils.RequiresNotNullItems(indexes, "args");
76 return target.BindSetIndex(this, indexes, value);
79 // this is a standard DynamicMetaObjectBinder
80 internal override sealed bool IsStandardBinder {
87 /// Performs the binding of the dynamic set index operation if the target dynamic object cannot bind.
89 /// <param name="target">The target of the dynamic set index operation.</param>
90 /// <param name="indexes">The arguments of the dynamic set index operation.</param>
91 /// <param name="value">The value to set to the collection.</param>
92 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
93 public DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value) {
94 return FallbackSetIndex(target, indexes, value, null);
98 /// When overridden in the derived class, performs the binding of the dynamic set index operation if the target dynamic object cannot bind.
100 /// <param name="target">The target of the dynamic set index operation.</param>
101 /// <param name="indexes">The arguments of the dynamic set index operation.</param>
102 /// <param name="value">The value to set to the collection.</param>
103 /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
104 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
105 public abstract DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion);