获得反射的方法并执行 - GetMethodInfoValue

2017-02-26 15:47:06  访问(1334) 赞(0) 踩(0)


        /// <summary>
        /// 获得反射的方法并执行 - GetMethodInfoValue
        /// </summary>
        /// <param name="oThis"></param>
        /// <param name="methodInfoName"></param>
        /// <param name="oArray"></param>
        /// <returns></returns>
        public static object GetMethodInfoValue(object oThis, string methodInfoName,object [] oArray)
        {
            if (oThis == null)
            {

                throw new Exception
                    (
                        "方法:"
                        + MethodBase.GetCurrentMethod().ReflectedType.FullName
                        + " "
                        + MethodBase.GetCurrentMethod().ToString()
                        + " 发生异常:"
                        + "传入参数:object oThis为null。"
                    );
            }

            Type tThis = oThis.GetType();

            MethodInfo methodInfoValue = tThis.GetMethod(methodInfoName);

            if (methodInfoValue == null)
            {

                throw new Exception
                    (
                        "方法:"
                        + MethodBase.GetCurrentMethod().ReflectedType.FullName
                        + " "
                        + MethodBase.GetCurrentMethod().ToString()
                        + " 发生异常:MethodInfo methodInfoValue = tThis.GetMethod(methodInfoName[" + methodInfoName + "])值为null。"
                    );
            }  

            return methodInfoValue.Invoke(oThis, oArray);
        }


标签:获得反射的方法并执行 - GetMethodInfoValue 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)