2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Actions / InvokeMemberBinder.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 member dynamic operation at the call site,
32     /// providing the binding semantic and the details about the operation.
33     /// </summary>
34     public abstract class InvokeMemberBinder : DynamicMetaObjectBinder {
35         private readonly string _name;
36         private readonly bool _ignoreCase;
37         private readonly CallInfo _callInfo;
38
39         /// <summary>
40         /// Initializes a new instance of the <see cref="InvokeMemberBinder" />.
41         /// </summary>
42         /// <param name="name">The name of the member to invoke.</param>
43         /// <param name="ignoreCase">true if the name should be matched ignoring case; false otherwise.</param>
44         /// <param name="callInfo">The signature of the arguments at the call site.</param>
45         protected InvokeMemberBinder(string name, bool ignoreCase, CallInfo callInfo) {
46             ContractUtils.RequiresNotNull(name, "name");
47             ContractUtils.RequiresNotNull(callInfo, "callInfo");
48
49             _name = name;
50             _ignoreCase = ignoreCase;
51             _callInfo = callInfo;
52         }
53
54         /// <summary>
55         /// The result type of the operation.
56         /// </summary>
57         public override sealed Type ReturnType {
58             get { return typeof(object); }
59         }
60
61         /// <summary>
62         /// Gets the name of the member to invoke.
63         /// </summary>
64         public string Name {
65             get {
66                 return _name;
67             }
68         }
69
70         /// <summary>
71         /// Gets the value indicating if the string comparison should ignore the case of the member name.
72         /// </summary>
73         public bool IgnoreCase {
74             get {
75                 return _ignoreCase;
76             }
77         }
78
79         /// <summary>
80         /// Gets the signature of the arguments at the call site.
81         /// </summary>
82         public CallInfo CallInfo {
83             get { return _callInfo; }
84         }
85
86         /// <summary>
87         /// Performs the binding of the dynamic invoke member operation.
88         /// </summary>
89         /// <param name="target">The target of the dynamic invoke member operation.</param>
90         /// <param name="args">An array of arguments of the dynamic invoke member operation.</param>
91         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
92         public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
93             ContractUtils.RequiresNotNull(target, "target");
94             ContractUtils.RequiresNotNullItems(args, "args");
95
96             return target.BindInvokeMember(this, args);
97         }
98
99         // this is a standard DynamicMetaObjectBinder
100         internal override sealed bool IsStandardBinder {
101             get {
102                 return true;
103             }
104         }
105
106         /// <summary>
107         /// Performs the binding of the dynamic invoke member operation if the target dynamic object cannot bind.
108         /// </summary>
109         /// <param name="target">The target of the dynamic invoke member operation.</param>
110         /// <param name="args">The arguments of the dynamic invoke member operation.</param>
111         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
112         public DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args) {
113             return FallbackInvokeMember(target, args, null);
114         }
115
116         /// <summary>
117         /// When overridden in the derived class, performs the binding of the dynamic invoke member operation if the target dynamic object cannot bind.
118         /// </summary>
119         /// <param name="target">The target of the dynamic invoke member operation.</param>
120         /// <param name="args">The arguments of the dynamic invoke member operation.</param>
121         /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
122         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
123         public abstract DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion);
124
125         /// <summary>
126         /// When overridden in the derived class, performs the binding of the dynamic invoke operation if the target dynamic object cannot bind.
127         /// </summary>
128         /// <param name="target">The target of the dynamic invoke operation.</param>
129         /// <param name="args">The arguments of the dynamic invoke operation.</param>
130         /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
131         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
132         /// <remarks>
133         /// This method is called by the target when the target implements the invoke member operation
134         /// as a sequence of get member, and invoke, to let the <see cref="DynamicMetaObject"/>
135         /// request the binding of the invoke operation only.
136         /// </remarks>
137         public abstract DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion);
138     }
139 }