PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 88 lines | 30 code | 11 blank | 47 comment | 0 complexity | 9b343bc1b309737b32d56ec8b8681591 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 index operation at the call site, providing the binding semantic and the details about the operation.
  19. /// </summary>
  20. public abstract class GetIndexBinder : DynamicMetaObjectBinder {
  21. private readonly CallInfo _callInfo;
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="GetIndexBinder" />.
  24. /// </summary>
  25. /// <param name="callInfo">The signature of the arguments at the call site.</param>
  26. protected GetIndexBinder(CallInfo callInfo) {
  27. ContractUtils.RequiresNotNull(callInfo, "callInfo");
  28. _callInfo = callInfo;
  29. }
  30. /// <summary>
  31. /// The result type of the operation.
  32. /// </summary>
  33. public override sealed Type ReturnType {
  34. get { return typeof(object); }
  35. }
  36. /// <summary>
  37. /// Gets the signature of the arguments at the call site.
  38. /// </summary>
  39. public CallInfo CallInfo {
  40. get { return _callInfo; }
  41. }
  42. /// <summary>
  43. /// Performs the binding of the dynamic get index operation.
  44. /// </summary>
  45. /// <param name="target">The target of the dynamic get index operation.</param>
  46. /// <param name="args">An array of arguments of the dynamic get index operation.</param>
  47. /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
  48. public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
  49. ContractUtils.RequiresNotNull(target, "target");
  50. ContractUtils.RequiresNotNullItems(args, "args");
  51. return target.BindGetIndex(this, args);
  52. }
  53. // this is a standard DynamicMetaObjectBinder
  54. internal override sealed bool IsStandardBinder {
  55. get {
  56. return true;
  57. }
  58. }
  59. /// <summary>
  60. /// Performs the binding of the dynamic get index operation if the target dynamic object cannot bind.
  61. /// </summary>
  62. /// <param name="target">The target of the dynamic get index operation.</param>
  63. /// <param name="indexes">The arguments of the dynamic get index operation.</param>
  64. /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
  65. public DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes) {
  66. return FallbackGetIndex(target, indexes, null);
  67. }
  68. /// <summary>
  69. /// When overridden in the derived class, performs the binding of the dynamic get index operation if the target dynamic object cannot bind.
  70. /// </summary>
  71. /// <param name="target">The target of the dynamic get index operation.</param>
  72. /// <param name="indexes">The arguments of the dynamic get index operation.</param>
  73. /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
  74. /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
  75. public abstract DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion);
  76. }
  77. }