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