usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceResourceDemo{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();// Reso_1();Reso_2();}/// <summary>/// 调用资源文件中类的方法/// 方法中包含参数、没有返回值/// </summary>voidReso_1(){//资源文件中的类object obj;//资源文件中的DLLSystem.Reflection.Assembly ass =System.Reflection.Assembly.Load(ResourceDemo.Properties.Resources.PackDLL);//获取DLL中的类型(命名空间+类的方法名称)Type type = ass.GetType("PackDLL.FileAndDir.Log.PackApplicaitonLog");//获取类中的方法(第一个参数类的方法名称,第二个参数是)System.Reflection.MethodInfo mi = type.GetMethod("WriteLog",newType[]{typeof(string),typeof(string),typeof(string)});//创建资源文件中类的实例(命名空间+类的方法名称)obj= ass.CreateInstance("PackDLL.FileAndDir.Log.PackApplicaitonLog");//调用资源文件中类的方法(第一个参数类的实例,第二个参数列表)mi.Invoke(obj,newobject[]{"app","app.txt","我定义了异常"});}/// <summary>/// 调用资源文件中类的方法/// 方法中不包含参数、带有返回值/// </summary>voidReso_2(){//PackDLL.Local.Localhost.PackComputerPhysics.GetCpuID//资源文件中的类object obj;//资源文件中的DLLSystem.Reflection.Assembly ass =System.Reflection.Assembly.Load(ResourceDemo.Properties.Resources.PackDLL);//获取DLL中的类型(命名空间+类的方法名称)Type type = ass.GetType("PackDLL.Local.Localhost.PackComputerPhysics");//获取类中的方法(第一个参数类的方法名称,第二个参数是)System.Reflection.MethodInfo mi = type.GetMethod("GetCpuID");//创建资源文件中类的实例(命名空间+类的方法名称)obj= ass.CreateInstance("PackDLL.Local.Localhost.PackComputerPhysics");//调用方法,如果方法中不包含参数,invoke第二个参数列表可以用null代替string cpuId = mi.Invoke(obj,null).ToString();}}}