PageRenderTime 54ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 97 lines | 35 code | 13 blank | 49 comment | 0 complexity | 7fa6a0ffc3ddc549392f63cdfe6ddd1c 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 set index operation at the call site, providing the binding semantic and the details about the operation.
  19. /// </summary>
  20. public abstract class SetIndexBinder : DynamicMetaObjectBinder {
  21. private readonly CallInfo _callInfo;
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="SetIndexBinder" />.
  24. /// </summary>
  25. /// <param name="callInfo">The signature of the arguments at the call site.</param>
  26. protected SetIndexBinder(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 set index operation.
  44. /// </summary>
  45. /// <param name="target">The target of the dynamic set index operation.</param>
  46. /// <param name="args">An array of arguments of the dynamic set 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.RequiresNotNull(args, "args");
  51. ContractUtils.Requires(args.Length >= 2, "args");
  52. DynamicMetaObject value = args[args.Length - 1];
  53. DynamicMetaObject[] indexes = args.RemoveLast();
  54. ContractUtils.RequiresNotNull(value, "args");
  55. ContractUtils.RequiresNotNullItems(indexes, "args");
  56. return target.BindSetIndex(this, indexes, value);
  57. }
  58. // this is a standard DynamicMetaObjectBinder
  59. internal override sealed bool IsStandardBinder {
  60. get {
  61. return true;
  62. }
  63. }
  64. /// <summary>
  65. /// Performs the binding of the dynamic set index operation if the target dynamic object cannot bind.
  66. /// </summary>
  67. /// <param name="target">The target of the dynamic set index operation.</param>
  68. /// <param name="indexes">The arguments of the dynamic set index operation.</param>
  69. /// <param name="value">The value to set to the collection.</param>
  70. /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
  71. public DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value) {
  72. return FallbackSetIndex(target, indexes, value, null);
  73. }
  74. /// <summary>
  75. /// When overridden in the derived class, performs the binding of the dynamic set index operation if the target dynamic object cannot bind.
  76. /// </summary>
  77. /// <param name="target">The target of the dynamic set index operation.</param>
  78. /// <param name="indexes">The arguments of the dynamic set index operation.</param>
  79. /// <param name="value">The value to set to the collection.</param>
  80. /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
  81. /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
  82. public abstract DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion);
  83. }
  84. }