PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_2_0/Src/Microsoft.Scripting/Generation/DelegateHelpers.Generated.cs

#
C# | 109 lines | 66 code | 18 blank | 25 comment | 9 complexity | ed89507cf74e3a8bf44c6de1987a2f42 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 Microsoft Public License. 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 Microsoft Public License, 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 Microsoft Public License.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System; using Microsoft;
  16. using System.Diagnostics;
  17. using Microsoft.Scripting.Utils;
  18. namespace Microsoft.Scripting.Generation {
  19. internal static partial class DelegateHelpers {
  20. #region Generated Maximum Delegate Arity
  21. // *** BEGIN GENERATED CODE ***
  22. // generated by function: gen_max_delegate_arity from: generate_dynsites.py
  23. private const int MaximumArity = 17;
  24. // *** END GENERATED CODE ***
  25. #endregion
  26. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
  27. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
  28. internal static Type MakeDelegate(Type[] types) {
  29. Debug.Assert(types != null && types.Length > 0);
  30. // Can only used predefined delegates if we have no byref types and
  31. // the arity is small enough to fit in Func<...> or Action<...>
  32. if (types.Length > MaximumArity || types.Any(t => t.IsByRef)) {
  33. return MakeCustomDelegate(types);
  34. }
  35. Type returnType = types[types.Length - 1];
  36. if (returnType == typeof(void)) {
  37. types = types.RemoveLast();
  38. switch (types.Length) {
  39. case 0: return typeof(Action);
  40. #region Generated Delegate Action Types
  41. // *** BEGIN GENERATED CODE ***
  42. // generated by function: gen_delegate_action from: generate_dynsites.py
  43. case 1: return typeof(Action<>).MakeGenericType(types);
  44. case 2: return typeof(Action<,>).MakeGenericType(types);
  45. case 3: return typeof(Action<,,>).MakeGenericType(types);
  46. case 4: return typeof(Action<,,,>).MakeGenericType(types);
  47. case 5: return typeof(Action<,,,,>).MakeGenericType(types);
  48. case 6: return typeof(Action<,,,,,>).MakeGenericType(types);
  49. case 7: return typeof(Action<,,,,,,>).MakeGenericType(types);
  50. case 8: return typeof(Action<,,,,,,,>).MakeGenericType(types);
  51. case 9: return typeof(Action<,,,,,,,,>).MakeGenericType(types);
  52. case 10: return typeof(Action<,,,,,,,,,>).MakeGenericType(types);
  53. case 11: return typeof(Action<,,,,,,,,,,>).MakeGenericType(types);
  54. case 12: return typeof(Action<,,,,,,,,,,,>).MakeGenericType(types);
  55. case 13: return typeof(Action<,,,,,,,,,,,,>).MakeGenericType(types);
  56. case 14: return typeof(Action<,,,,,,,,,,,,,>).MakeGenericType(types);
  57. case 15: return typeof(Action<,,,,,,,,,,,,,,>).MakeGenericType(types);
  58. case 16: return typeof(Action<,,,,,,,,,,,,,,,>).MakeGenericType(types);
  59. // *** END GENERATED CODE ***
  60. #endregion
  61. }
  62. } else {
  63. switch (types.Length) {
  64. #region Generated Delegate Func Types
  65. // *** BEGIN GENERATED CODE ***
  66. // generated by function: gen_delegate_func from: generate_dynsites.py
  67. case 1: return typeof(Func<>).MakeGenericType(types);
  68. case 2: return typeof(Func<,>).MakeGenericType(types);
  69. case 3: return typeof(Func<,,>).MakeGenericType(types);
  70. case 4: return typeof(Func<,,,>).MakeGenericType(types);
  71. case 5: return typeof(Func<,,,,>).MakeGenericType(types);
  72. case 6: return typeof(Func<,,,,,>).MakeGenericType(types);
  73. case 7: return typeof(Func<,,,,,,>).MakeGenericType(types);
  74. case 8: return typeof(Func<,,,,,,,>).MakeGenericType(types);
  75. case 9: return typeof(Func<,,,,,,,,>).MakeGenericType(types);
  76. case 10: return typeof(Func<,,,,,,,,,>).MakeGenericType(types);
  77. case 11: return typeof(Func<,,,,,,,,,,>).MakeGenericType(types);
  78. case 12: return typeof(Func<,,,,,,,,,,,>).MakeGenericType(types);
  79. case 13: return typeof(Func<,,,,,,,,,,,,>).MakeGenericType(types);
  80. case 14: return typeof(Func<,,,,,,,,,,,,,>).MakeGenericType(types);
  81. case 15: return typeof(Func<,,,,,,,,,,,,,,>).MakeGenericType(types);
  82. case 16: return typeof(Func<,,,,,,,,,,,,,,,>).MakeGenericType(types);
  83. case 17: return typeof(Func<,,,,,,,,,,,,,,,,>).MakeGenericType(types);
  84. // *** END GENERATED CODE ***
  85. #endregion
  86. }
  87. }
  88. throw Assert.Unreachable;
  89. }
  90. }
  91. }