泛型实例化,楼主参考: public static ISqlHelperX<T> CreateSqlHelperX<T>() where T : new() { Assembly a = Assembly.Load(path); Type t = a.GetType((path +".SqlHelperX`1"); Type[] typeArgs = { typeof(T) }; Type constructed = t.MakeGenericType(typeArgs); return (ISqlHelperX<T>)System.Activator.CreateInstance(constructed); }
因为他是泛型,且带版本号,会不会有不确定?
因为他是泛型,且带版本号,会不会有不确定?
你可以用 typeof(T).AssemblyQualifiedName 代替FullName参与拼接
http://msdn.microsoft.com/zh-cn/library/system.type.makegenerictype.aspx
public static ISqlHelperX<T> CreateSqlHelperX<T>()
where T : new()
{
Assembly a = Assembly.Load(path);
Type t = a.GetType((path +".SqlHelperX`1");
Type[] typeArgs = { typeof(T) };
Type constructed = t.MakeGenericType(typeArgs);
return (ISqlHelperX<T>)System.Activator.CreateInstance(constructed);
}