不同应用程序域中访问数据!(反射)
- 作者:zhaozj
- 发表时间:2020-12-23 10:39
- 来源:未知
private void button1_Click(object sender, System.EventArgs e) { Evidence asEvidence = currentDomain.Evidence; currentDomain.Load("WindowsApplication2",asEvidence); Assembly[] assems = currentDomain.GetAssemblies();
Console.WriteLine("List of assemblies loaded in current appdomain:"); foreach (Assembly assem in assems) { Type t = assem.GetType("WindowsApplication2.Form1"); if (t != null ) { FieldInfo [] fs= t.GetFields(); foreach( FieldInfo f in fs) { if("val" == f.Name) { f.SetValue(null,"Hello world!"); Console.WriteLine(f.GetValue(null).ToString()); } } } } }
WindowsApplication2.From1中声明
public static String val = "test";