2012-04-22 34 views

回答

2

您可以将程序集的名称放在app.config文件中,然后使用Assembly.Load选项和反射在运行时加载它。这里是MSDN文章描述如何做到这一点的链接。

http://msdn.microsoft.com/en-us/library/25y1ya39.aspx

基础在app.config文件汇编的

  1. 认沽名
  2. 使用ConfigurationManager中,并获得名字进入你的程序中的字符串读条目
  3. 传递的名称装配到Assembly.Load方法。从链路

实施例:

public class Asmload0 
{ 
    public static void Main() 
    { 
     // Use the file name to load the assembly into the current 
     // application domain. 
     Assembly a = Assembly.Load("example"); 
     // Get the type to use. 
     Type myType = a.GetType("Example"); 
     // Get the method to call. 
     MethodInfo myMethod = myType.GetMethod("MethodA"); 
     // Create an instance. 
     object obj = Activator.CreateInstance(myType); 
     // Execute the method. 
     myMethod.Invoke(obj, null); 
    } 
} 
相关问题