首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

反射DLL示例 C#

Posted on 2010-05-13 14:31  达奇  阅读(394)  评论(0编辑  收藏  举报
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Dachie
{
    class Program
    {
        static void Main(string[] args)
        {
            Assembly a = Assembly.LoadFrom(@"DLL文件绝对路径");
            Type[] mytypes = a.GetTypes();
            BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
                BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            foreach (Type t in mytypes)
            {
                MethodInfo[] mi = t.GetMethods(flags);
                Object obj = Activator.CreateInstance(t);

                foreach (MethodInfo m in mi)
                {
                    m.Invoke(obj, null);
                }
            }
        }
    }
}