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 {
20 /// Represents the dynamic get member operation at the call site, providing the binding semantic and the details about the operation.
22 public abstract class GetMemberBinder : DynamicMetaObjectBinder {
23 private readonly string _name;
24 private readonly bool _ignoreCase;
27 /// Initializes a new instance of the <see cref="GetMemberBinder" />.
29 /// <param name="name">The name of the member to get.</param>
30 /// <param name="ignoreCase">true if the name should be matched ignoring case; false otherwise.</param>
31 protected GetMemberBinder(string name, bool ignoreCase) {
32 ContractUtils.RequiresNotNull(name, "name");
35 _ignoreCase = ignoreCase;
39 /// The result type of the operation.
41 public override sealed Type ReturnType {
42 get { return typeof(object); }
46 /// Gets the name of the member to get.
55 /// Gets the value indicating if the string comparison should ignore the case of the member name.
57 public bool IgnoreCase {
64 /// Performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
66 /// <param name="target">The target of the dynamic get member operation.</param>
67 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
68 public DynamicMetaObject FallbackGetMember(DynamicMetaObject target) {
69 return FallbackGetMember(target, null);
73 /// When overridden in the derived class, performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
75 /// <param name="target">The target of the dynamic get member operation.</param>
76 /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
77 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
78 public abstract DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion);
81 /// Performs the binding of the dynamic get member operation.
83 /// <param name="target">The target of the dynamic get member operation.</param>
84 /// <param name="args">An array of arguments of the dynamic get member operation.</param>
85 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
86 public sealed override DynamicMetaObject Bind(DynamicMetaObject target, params DynamicMetaObject[] args) {
87 ContractUtils.RequiresNotNull(target, "target");
88 ContractUtils.Requires(args == null || args.Length == 0, "args");
90 return target.BindGetMember(this);
93 // this is a standard DynamicMetaObjectBinder
94 internal override sealed bool IsStandardBinder {