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 {
30 /// Represents the dynamic get member operation at the call site, providing the binding semantic and the details about the operation.
32 public abstract class GetMemberBinder : DynamicMetaObjectBinder {
33 private readonly string _name;
34 private readonly bool _ignoreCase;
37 /// Initializes a new instance of the <see cref="GetMemberBinder" />.
39 /// <param name="name">The name of the member to get.</param>
40 /// <param name="ignoreCase">true if the name should be matched ignoring case; false otherwise.</param>
41 protected GetMemberBinder(string name, bool ignoreCase) {
42 ContractUtils.RequiresNotNull(name, "name");
45 _ignoreCase = ignoreCase;
49 /// The result type of the operation.
51 public override sealed Type ReturnType {
52 get { return typeof(object); }
56 /// Gets the name of the member to get.
65 /// Gets the value indicating if the string comparison should ignore the case of the member name.
67 public bool IgnoreCase {
74 /// Performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
76 /// <param name="target">The target of the dynamic get member operation.</param>
77 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
78 public DynamicMetaObject FallbackGetMember(DynamicMetaObject target) {
79 return FallbackGetMember(target, null);
83 /// When overridden in the derived class, performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
85 /// <param name="target">The target of the dynamic get member operation.</param>
86 /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
87 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
88 public abstract DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion);
91 /// Performs the binding of the dynamic get member operation.
93 /// <param name="target">The target of the dynamic get member operation.</param>
94 /// <param name="args">An array of arguments of the dynamic get member operation.</param>
95 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
96 public sealed override DynamicMetaObject Bind(DynamicMetaObject target, params DynamicMetaObject[] args) {
97 ContractUtils.RequiresNotNull(target, "target");
98 ContractUtils.Requires(args == null || args.Length == 0, "args");
100 return target.BindGetMember(this);
103 // this is a standard DynamicMetaObjectBinder
104 internal override sealed bool IsStandardBinder {