1. 用Type

   在 website 下

C#代码  
//定义参数类型数组  
Type[] tps = new Type[2];  
tps[0] = typeof(int);  
tps[1] = typeof(string);  
  
//定义参数数组  
object[] obj = new object[2];  
obj[0] = (object)100;  
obj[1] = (object)"Param Example";  
  
string UserDaoPath = System.Configuration.ConfigurationSettings.AppSettings["UserDao"];  
UserDao userDao = (UserDao)Type.GetType(UserDaoPath).  
            GetConstructor(tps).Invoke(obj );  

2. 用Assembly
在 website 下 这个是导入一个 程序集 然后在程序集里再 实例化类, 我这里其实就是实例化一个类。

C#代码  
string UserServicePath = System.Configuration.ConfigurationSettings  
                                        .AppSettings["UserService"];  
UserService userService = (IUserService)Assembly.Load(UserServicePath).  
            CreateInstance("UserService");  
 
C#代码  
<appSettings >  
    <add key="UserService" value="App_Code.Service.UserService"></add>  
</appSettings>  

  

相关文章:

  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
猜你喜欢
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
相关资源
相似解决方案