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