C#中的反射

作者在 2009-01-02 16:58:11 发布以下内容

string[] arFile =

 System.IO.Directory.GetFiles(Application.StartupPath, "DLLForm.dll");

            for (int i = 0; i < arFile.Length; i++)

            {

                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(arFile[i]);

                foreach (Type type in assembly.GetTypes())

                {

                    object myForm = Activator.CreateInstance(type) as Form;

                    if (myForm != null)

                    {

                        ((Form)myForm).ShowDialog();

                        return;

                    }

                }

         }

结果如下:(记得运行前将DLLForm这个DLLMyApplication放在同一个目录下,否则你要使用绝对路径)

默认分类 | 阅读 5202 次
文章评论,共0条
游客请输入验证码
浏览32193次
文章归档
最新评论