反射DLL例C#

1447 ワード

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);

                }

            }

        }

    }

}