public DynamicMethodHandle(System.Reflection.MethodInfo info, params object[] parameters)
 {
     if (info == null)
     {
         this.DynamicMethod = null;
     }
     else
     {
         this.MethodName = info.Name;
         var      infoParams = info.GetParameters();
         object[] inParams   = null;
         if (parameters == null)
         {
             inParams = new object[] { null };
         }
         else
         {
             inParams = parameters;
         }
         var pCount = infoParams.Length;
         if (pCount > 0 &&
             ((pCount == 1 && infoParams[0].ParameterType.IsArray) ||
              (infoParams[pCount - 1].GetCustomAttributes(typeof(ParamArrayAttribute), true).Length > 0)))
         {
             this.HasFinalArrayParam    = true;
             this.MethodParamsLength    = pCount;
             this.FinalArrayElementType = infoParams[pCount - 1].ParameterType;
         }
         this.DynamicMethod = DynamicMethodHandlerFactory.CreateMethod(info);
     }
 }
예제 #2
0
        /// <summary>
        /// Initializes and caches the metastate values
        /// necessary to invoke the method
        /// </summary>
        public void PrepForInvocation()
        {
            if (!_initialized)
            {
                lock (MethodInfo)
                {
                    if (!_initialized)
                    {
                        DynamicMethod   = DynamicMethodHandlerFactory.CreateMethod(MethodInfo);
                        Parameters      = MethodInfo.GetParameters();
                        TakesParamArray = (Parameters.Length == 1 && Parameters[0].ParameterType.Equals(typeof(object[])));
                        IsInjected      = new bool[Parameters.Length];

                        int index = 0;
                        foreach (var item in Parameters)
                        {
                            if (item.GetCustomAttributes <InjectAttribute>().Any())
                            {
                                IsInjected[index] = true;
                            }
                            index++;
                        }
                        IsAsyncTask          = (MethodInfo.ReturnType == typeof(Task));
                        IsAsyncTaskObject    = (MethodInfo.ReturnType.IsGenericType && (MethodInfo.ReturnType.GetGenericTypeDefinition() == typeof(Task <>)));
                        DataPortalMethodInfo = new DataPortalMethodInfo(MethodInfo);

                        _initialized = true;
                    }
                }
            }
        }
예제 #3
0
        public DynamicMethodHandle(System.Reflection.MethodInfo info, params object[] parameters)
        {
            if (info == null)
            {
                this.DynamicMethod = null;
            }
            else
            {
                this.MethodName = info.Name;
                var      infoParams = info.GetParameters();
                object[] inParams   = null;
                if (parameters == null)
                {
                    inParams = new object[] { null };
                }
                else
                {
                    inParams = parameters;
                }
                var pCount = infoParams.Length;
#if NETFX_CORE
                var isgeneric = info.ReturnType.IsGenericType();
                if (pCount > 0 &&
                    ((pCount == 1 && infoParams[0].ParameterType.IsArray) ||
                     (infoParams[pCount - 1].GetCustomAttributes(typeof(ParamArrayAttribute), true).Count() > 0)))
#else
                var isgeneric = info.ReturnType.IsGenericType;
                if (pCount > 0 &&
                    ((pCount == 1 && infoParams[0].ParameterType.IsArray) ||
                     (infoParams[pCount - 1].GetCustomAttributes(typeof(ParamArrayAttribute), true).Length > 0)))
#endif
                {
                    this.HasFinalArrayParam    = true;
                    this.MethodParamsLength    = pCount;
                    this.FinalArrayElementType = infoParams[pCount - 1].ParameterType;
                }
                IsAsyncTask        = (info.ReturnType == typeof(System.Threading.Tasks.Task));
                IsAsyncTaskObject  = (isgeneric && (info.ReturnType.GetGenericTypeDefinition() == typeof(System.Threading.Tasks.Task <>)));
                this.DynamicMethod = DynamicMethodHandlerFactory.CreateMethod(info);
            }
        }