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 invoke member dynamic operation at the call site,
32 /// providing the binding semantic and the details about the operation.
34 public abstract class InvokeMemberBinder : DynamicMetaObjectBinder {
35 private readonly string _name;
36 private readonly bool _ignoreCase;
37 private readonly CallInfo _callInfo;
40 /// Initializes a new instance of the <see cref="InvokeMemberBinder" />.
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");
50 _ignoreCase = ignoreCase;
55 /// The result type of the operation.
57 public override sealed Type ReturnType {
58 get { return typeof(object); }
62 /// Gets the name of the member to invoke.
71 /// Gets the value indicating if the string comparison should ignore the case of the member name.
73 public bool IgnoreCase {
80 /// Gets the signature of the arguments at the call site.
82 public CallInfo CallInfo {
83 get { return _callInfo; }
87 /// Performs the binding of the dynamic invoke member operation.
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");
96 return target.BindInvokeMember(this, args);
99 // this is a standard DynamicMetaObjectBinder
100 internal override sealed bool IsStandardBinder {
107 /// Performs the binding of the dynamic invoke member operation if the target dynamic object cannot bind.
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);
117 /// When overridden in the derived class, performs the binding of the dynamic invoke member operation if the target dynamic object cannot bind.
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);
126 /// When overridden in the derived class, performs the binding of the dynamic invoke operation if the target dynamic object cannot bind.
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>
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.
137 public abstract DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion);