.NET 反射应用

 object request = null;

            string requestObjClassName = "命名空间"
                           + 类型.ToString();
            Type type = Type.GetType(requestObjClassName);

            object[] args = new object[] { objRequired, objAdditional };
            RequestObj requestObj = null;
            try
            {
                requestObj = Activator.CreateInstance(type, args) as RequestObj;

                request = new object(dataContext, requestId, requestObj);
            }
            catch (Exception ex)
            {
                LoggerHelper.LogError(string.Format("Create request object failed {0}", requestType.ToString()), ex);
                throw ex;
            }

 

posted @ 2017-11-28 11:41  白羽轻飘  阅读(105)  评论(0编辑  收藏  举报