PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 1ms 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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  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. using System.Dynamic.Utils;
  16. namespace System.Dynamic {
  17. /// <summary>
  18. /// Represents the dynamic get member operation at the call site, providing the binding semantic and the details about the operation.
  19. /// </summary>
  20. public abstract class GetMemberBinder : DynamicMetaObjectBinder {
  21. private readonly string _name;
  22. private readonly bool _ignoreCase;
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref="GetMemberBinder" />.
  25. /// </summary>
  26. /// <param name="name">The name of the member to get.</param>
  27. /// <param name="ignoreCase">true if the name should be matched ignoring case; false otherwise.</param>
  28. protected GetMemberBinder(string name, bool ignoreCase) {
  29. ContractUtils.RequiresNotNull(name, "name");
  30. _name = name;
  31. _ignoreCase = ignoreCase;
  32. }
  33. /// <summary>
  34. /// The result type of the operation.
  35. /// </summary>
  36. public override sealed Type ReturnType {
  37. get { return typeof(object); }
  38. }
  39. /// <summary>
  40. /// Gets the name of the member to get.
  41. /// </summary>
  42. public string Name {
  43. get {
  44. return _name;
  45. }
  46. }
  47. /// <summary>
  48. /// Gets the value indicating if the string comparison should ignore the case of the member name.
  49. /// </summary>
  50. public bool IgnoreCase {
  51. get {
  52. return _ignoreCase;
  53. }
  54. }
  55. /// <summary>
  56. /// Performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
  57. /// </summary>
  58. /// <param name="target">The target of the dynamic get member operation.</param>
  59. /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
  60. public DynamicMetaObject FallbackGetMember(DynamicMetaObject target) {
  61. return FallbackGetMember(target, null);
  62. }
  63. /// <summary>
  64. /// When overridden in the derived class, 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. /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
  68. /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
  69. public abstract DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion);
  70. /// <summary>
  71. /// Performs the binding of the dynamic get member operation.
  72. /// </summary>
  73. /// <param name="target">The target of the dynamic get member operation.</param>
  74. /// <param name="args">An array of arguments of the dynamic get member operation.</param>
  75. /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
  76. public sealed override DynamicMetaObject Bind(DynamicMetaObject target, params DynamicMetaObject[] args) {
  77. ContractUtils.RequiresNotNull(target, "target");
  78. ContractUtils.Requires(args == null || args.Length == 0, "args");
  79. return target.BindGetMember(this);
  80. }
  81. // this is a standard DynamicMetaObjectBinder
  82. internal override sealed bool IsStandardBinder {
  83. get {
  84. return true;
  85. }
  86. }
  87. }
  88. }