反射(Assembly)

来源:互联网 发布:手游辅助软件 编辑:程序博客网 时间:2024/04/29 22:31
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";        }    }}

原创粉丝点击