コード例 #1
0
        /// <summary>
        /// Creates a new instance of the safe method wrapper.
        /// </summary>
        /// <param name="methodInfo">Method to wrap.</param>
        public SafeMethod(MethodInfo methodInfo)
        {
            Guard.ArgumentNotNull(methodInfo, "methodInfo", "You cannot create a dynamic method for a null value.");

            this.methodInfo = methodInfo;
            this.Name       = methodInfo.Name;
            ParameterInfo[] infoParams = methodInfo.GetParameters();
            int             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.method = DynamicReflectionManager.CreateMethod(methodInfo);
        }