普通类实例化:
Assembly assembly = Assembly.Load("Dsh.Data");
Type type = assembly.GetType("Dsh.Data.SqlServer");
Interface.IDal<TEntity> Dal = (Interface.IDal<TEntity>)Activator.CreateInstance(type, true);
泛型类实例化:(注意`1
)
Assembly assembly = Assembly.Load("Dsh.Data");
Type type = assembly.GetType("Dsh.Data.SqlServer" + "`1").MakeGenericType(typeof(TEntity));
Interface.IDal<TEntity> Dal = (Interface.IDal<TEntity>)Activator.CreateInstance(type, true);
泛型类(多个泛型)实例化:(注意`2
)
Assembly assembly = Assembly.Load("Dsh.Data");
Type type = assembly.GetType("Dsh.Data.SqlServer" + "`2").MakeGenericType(typeof(TEntity), typeof(TPrimaryKey));
Interface.IDal<TEntity, TPrimaryKey> = (Interface.IDal<TEntity, TPrimaryKey>)Activator.CreateInstance(type, true);
网友评论