c#反射执行静态方法

时间:2021-05-30 19:31:40

发射调用System.Environment.Exit(0)示例:

System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory+"\\xxx.dll"); 
//命名空间和类的名字必须一起指定
Type type = ass.GetType("System.Environment");

//使用16进制字符串:Type type = ass.GetType("0x53797374656d2e456e7669726f6e6d656e74"); 

object obj = type.InvokeMember("Exit",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Static
| System.Reflection.BindingFlags.Public, null, null,
new object[] {0});  //最后一个是参数:0

/*

object obj = type.InvokeMember("0x45786974",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Static 
| System.Reflection.BindingFlags.Public, null, null, 
new object[] {0});

*/

 

From:http://www.cnblogs.com/xuejianxiyang/p/7527228.html