PageRenderTime 26ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/IronPython_Main/Runtime/Microsoft.Scripting.Core/Actions/GetMemberBinder.cs

#
C# | 100 lines | 39 code | 12 blank | 49 comment | 3 complexity | f13bf5bec6132249a6048a384cf7fba8 MD5 | raw file
  1/* ****************************************************************************
  2 *
  3 * Copyright (c) Microsoft Corporation. 
  4 *
  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.
 10 *
 11 * You must not remove this notice, or any other, from this software.
 12 *
 13 *
 14 * ***************************************************************************/
 15
 16using System.Dynamic.Utils;
 17
 18namespace System.Dynamic {
 19    /// <summary>
 20    /// Represents the dynamic get member operation at the call site, providing the binding semantic and the details about the operation.
 21    /// </summary>
 22    public abstract class GetMemberBinder : DynamicMetaObjectBinder {
 23        private readonly string _name;
 24        private readonly bool _ignoreCase;
 25
 26        /// <summary>
 27        /// Initializes a new instance of the <see cref="GetMemberBinder" />.
 28        /// </summary>
 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");
 33
 34            _name = name;
 35            _ignoreCase = ignoreCase;
 36        }
 37
 38        /// <summary>
 39        /// The result type of the operation.
 40        /// </summary>
 41        public override sealed Type ReturnType {
 42            get { return typeof(object); }
 43        }
 44
 45        /// <summary>
 46        /// Gets the name of the member to get.
 47        /// </summary>
 48        public string Name {
 49            get {
 50                return _name;
 51            }
 52        }
 53
 54        /// <summary>
 55        /// Gets the value indicating if the string comparison should ignore the case of the member name.
 56        /// </summary>
 57        public bool IgnoreCase {
 58            get {
 59                return _ignoreCase;
 60            }
 61        }
 62
 63        /// <summary>
 64        /// Performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
 65        /// </summary>
 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);
 70        }
 71
 72        /// <summary>
 73        /// When overridden in the derived class, performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
 74        /// </summary>
 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);
 79
 80        /// <summary>
 81        /// Performs the binding of the dynamic get member operation.
 82        /// </summary>
 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");
 89
 90            return target.BindGetMember(this);
 91        }
 92
 93        // this is a standard DynamicMetaObjectBinder
 94        internal override sealed bool IsStandardBinder {
 95            get {
 96                return true;
 97            }
 98        }
 99    }
100}