下面的代码示例列出了程序集中每个方法的方法签名。 // LoadInvoke loads MyAssembly.dll and lists the method // information for each method. After compiling this class, // run LoadInvoke.exe with the DisplayName for the assembly, // as shown here: // LoadInvoke MyAssemblyusing System; using System.Reflection; using System.Security.Permissions;public class LoadInvoke { [PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")] public static void Main(string[] args) { Assembly a = Assembly.Load(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) { // Instead of invoking the methods, // it's safer to initially just list them. Console.WriteLine(m); } } } }using System.Reflection
// information for each method. After compiling this class,
// run LoadInvoke.exe with the DisplayName for the assembly,
// as shown here:
// LoadInvoke MyAssemblyusing System;
using System.Reflection;
using System.Security.Permissions;public class LoadInvoke
{
[PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")]
public static void Main(string[] args)
{
Assembly a = Assembly.Load(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)
{
// Instead of invoking the methods,
// it's safer to initially just list them.
Console.WriteLine(m);
}
}
}
}using System.Reflection