using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;//声明Assembly类需要引用该命名空间;
using System.Diagnostics;//声明Process类需要引用该命名空间
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Assembly asm = Assembly.LoadFrom(GetCurrent());//加载程序集
//通过反射创建asm实例对象
object obj = asm.CreateInstance("WindowsFormsApplication1.asm", true);
}
static string GetCurrent()
{
//获取应用程序路径
return AppDomain.CurrentDomain.BaseDirectory +
Process.GetCurrentProcess().ProcessName.Replace("vshost", "exe"); //Debug模式下换成exe;
}
}
class asm
{
public asm()
{
MessageBox.Show("Hello,"+GetName());
}
public string GetName()
{
return "Max";
}
}
}
反射(Assembly)
最新推荐文章于 2020-10-23 19:57:39 发布