// LoadInvoke loads MyAssembly.dll and invokes the MyMethod1 method. // After compiling this class, run LoadInvoke.exe with MyAssembly.dll // as the command line argument, as shown below: // LoadInvoke Myassembly.dllusing System; using System.Reflection; public class LoadInvoke { public static void Main(string[] args) { Assembly a = Assembly.LoadFrom(args[0]); 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); } } } }
// After compiling this class, run LoadInvoke.exe with MyAssembly.dll
// as the command line argument, as shown below:
// LoadInvoke Myassembly.dllusing System;
using System.Reflection;
public class LoadInvoke
{
public static void Main(string[] args)
{
Assembly a = Assembly.LoadFrom(args[0]);
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);
}
}
}
}
http://expert.csdn.net/Expert/topic/2214/2214138.xml?temp=.7600824