根据方法名反射到方法后去执行方法

 /// <summary>
        /// 根据方法名称反射调用相应的方法
        /// </summary>
        /// <param name="methodname"></param>
        public string InitCombox(string method)
        {
            Type type = this.GetType();
            MethodInfo m = type.GetMethod(method);
            if (m == null) throw new Exception("method is null");
            try
            {

            //如果需要传递参数 

      //object[] objs = { "参数1", "参数2", "参数3" };
               //objs = new object[] { objs};
                return m.Invoke(this, null).ToString();
            }
            catch (Exception)
            {
                throw new Exception("method is null");
            }
        }
        public string InitComboxOrgBigType()
        {
            return ConstDefine.OrgBigType;
        }

        public string InitComboxOrgSmallType()
        {
            return ConstDefine.OrgSmallType;
        }

        public string InitComboxOrgLevel()
        {
            return ConstDefine.OrgLevel;
        }

posted @ 2013-04-26 11:31  soulfree  阅读(329)  评论(0编辑  收藏  举报