1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
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.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
16 using System.Dynamic.Utils;
18 namespace System.Dynamic {
21 /// Represents the invoke member dynamic operation at the call site,
22 /// providing the binding semantic and the details about the operation.
24 public abstract class InvokeMemberBinder : DynamicMetaObjectBinder {
25 private readonly string _name;
26 private readonly bool _ignoreCase;
27 private readonly CallInfo _callInfo;
30 /// Initializes a new instance of the <see cref="InvokeMemberBinder" />.
32 /// <param name="name">The name of the member to invoke.</param>
33 /// <param name="ignoreCase">true if the name should be matched ignoring case; false otherwise.</param>
34 /// <param name="callInfo">The signature of the arguments at the call site.</param>
35 protected InvokeMemberBinder(string name, bool ignoreCase, CallInfo callInfo) {
36 ContractUtils.RequiresNotNull(name, "name");
37 ContractUtils.RequiresNotNull(callInfo, "callInfo");
40 _ignoreCase = ignoreCase;
45 /// The result type of the operation.
47 public override sealed Type ReturnType {
48 get { return typeof(object); }
52 /// Gets the name of the member to invoke.
61 /// Gets the value indicating if the string comparison should ignore the case of the member name.
63 public bool IgnoreCase {
70 /// Gets the signature of the arguments at the call site.
72 public CallInfo CallInfo {
73 get { return _callInfo; }
77 /// Performs the binding of the dynamic invoke member operation.
79 /// <param name="target">The target of the dynamic invoke member operation.</param>
80 /// <param name="args">An array of arguments of the dynamic invoke member operation.</param>
81 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
82 public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
83 ContractUtils.RequiresNotNull(target, "target");
84 ContractUtils.RequiresNotNullItems(args, "args");
86 return target.BindInvokeMember(this, args);
89 // this is a standard DynamicMetaObjectBinder
90 internal override sealed bool IsStandardBinder {
97 /// Performs the binding of the dynamic invoke member operation if the target dynamic object cannot bind.
99 /// <param name="target">The target of the dynamic invoke member operation.</param>
100 /// <param name="args">The arguments of the dynamic invoke member operation.</param>
101 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
102 public DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args) {
103 return FallbackInvokeMember(target, args, null);
107 /// When overridden in the derived class, 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 /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
112 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
113 public abstract DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion);
116 /// When overridden in the derived class, performs the binding of the dynamic invoke operation if the target dynamic object cannot bind.
118 /// <param name="target">The target of the dynamic invoke operation.</param>
119 /// <param name="args">The arguments of the dynamic invoke operation.</param>
120 /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
121 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
123 /// This method is called by the target when the target implements the invoke member operation
124 /// as a sequence of get member, and invoke, to let the <see cref="DynamicMetaObject"/>
125 /// request the binding of the invoke operation only.
127 public abstract DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion);