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";
博客展示了一段C#代码,在button1的点击事件里,加载了'WindowsApplication2'程序集,获取当前应用域中所有程序集。遍历程序集查找特定类型,若找到则获取其字段,将名为'val'的字段值设为'Hello world!'并输出。
103

被折叠的 条评论
为什么被折叠?



