/// <summary> /// 利用构造函数和参数快速实例化一个对象 /// </summary> /// <param name="constructorInfo"></param> /// <param name="parameters"></param> /// <returns></returns> public static object FastCreate(this ConstructorInfo constructorInfo, params object[] parameters) { if (constructorInfo == null) { throw new ArgumentNullException(nameof(constructorInfo)); } return(FastFactory.GetObjectCreatorWrapper(constructorInfo).Create(parameters)); }
/// <summary> /// 快速创建一个指定类型的对象 /// </summary> /// <param name="type"></param> /// <returns></returns> public static object FastCreate(this Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var constructorInfo = type.GetDefaultConstructor(); if (constructorInfo == null) { throw new ArgumentException("类型没有公开的默认构造函数。"); } return(FastFactory.GetObjectCreatorWrapper(constructorInfo).Create()); }