Example #1
0
        /// <summary>
        /// 动态创建实例
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="className">类名,包括命名空间,如果类型不处于当前执行程序集中,需要包含程序集名,范例:Test.Core.Test2,Test.Core</param>
        /// <param name="parameters">传递给构造函数的参数</param>
        public static T CreateInstance <T>(string className, params object[] parameters)
        {
            Type type = Type.GetType(className) ?? Assembly.GetCallingAssembly().GetType(className);

            return(Conv.To <T>(Activator.CreateInstance(type, parameters)));
        }