BindingFlags.Public needed here as Exception.HResult is now public in .NET 4.5. This...
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Actions / SetIndexBinder.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
5  * This source code is subject to terms and conditions of the Apache License, Version 2.0. 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  Apache License, Version 2.0, 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 Apache License, Version 2.0.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 using System.Dynamic.Utils;
17
18 namespace System.Dynamic {
19
20     /// <summary>
21     /// Represents the dynamic set index operation at the call site, providing the binding semantic and the details about the operation.
22     /// </summary>
23     public abstract class SetIndexBinder : DynamicMetaObjectBinder {
24         private readonly CallInfo _callInfo;
25
26         /// <summary>
27         /// Initializes a new instance of the <see cref="SetIndexBinder" />.
28         /// </summary>
29         /// <param name="callInfo">The signature of the arguments at the call site.</param>
30         protected SetIndexBinder(CallInfo callInfo) {
31             ContractUtils.RequiresNotNull(callInfo, "callInfo");
32             _callInfo = callInfo;
33         }
34
35         /// <summary>
36         /// The result type of the operation.
37         /// </summary>
38         public override sealed Type ReturnType {
39             get { return typeof(object); }
40         }
41
42         /// <summary>
43         /// Gets the signature of the arguments at the call site.
44         /// </summary>
45         public CallInfo CallInfo {
46             get { return _callInfo; }
47         }
48
49         /// <summary>
50         /// Performs the binding of the dynamic set index operation.
51         /// </summary>
52         /// <param name="target">The target of the dynamic set index operation.</param>
53         /// <param name="args">An array of arguments of the dynamic set 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.RequiresNotNull(args, "args");
58             ContractUtils.Requires(args.Length >= 2, "args");
59
60             DynamicMetaObject value = args[args.Length - 1];
61             DynamicMetaObject[] indexes = args.RemoveLast();
62
63             ContractUtils.RequiresNotNull(value, "args");
64             ContractUtils.RequiresNotNullItems(indexes, "args");
65
66             return target.BindSetIndex(this, indexes, value);
67         }
68
69         // this is a standard DynamicMetaObjectBinder
70         internal override sealed bool IsStandardBinder {
71             get {
72                 return true;
73             }
74         }
75
76         /// <summary>
77         /// Performs the binding of the dynamic set index operation if the target dynamic object cannot bind.
78         /// </summary>
79         /// <param name="target">The target of the dynamic set index operation.</param>
80         /// <param name="indexes">The arguments of the dynamic set index operation.</param>
81         /// <param name="value">The value to set to the collection.</param>
82         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
83         public DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value) {
84             return FallbackSetIndex(target, indexes, value, null);
85         }
86
87         /// <summary>
88         /// When overridden in the derived class, performs the binding of the dynamic set index operation if the target dynamic object cannot bind.
89         /// </summary>
90         /// <param name="target">The target of the dynamic set index operation.</param>
91         /// <param name="indexes">The arguments of the dynamic set index operation.</param>
92         /// <param name="value">The value to set to the collection.</param>
93         /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
94         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
95         public abstract DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion);
96     }
97 }