using System;
using C15_1;
using System.Reflection;
namespace C15_3
{
public class Reflector
{
public static void ReflectOnAssembly(Assembly assem)
{
WriteLine(0,"Assembly:{0}",assem);
//查找模組
foreach (Module m in assem.GetModules())
{
WriteLine(1,"Module:{0}", m);
//查找類型
foreach (Type t in m.GetTypes())
{
WriteLine(2, "Type:{0}", t);
//查找成員
foreach (MemberInfo mi in t.GetMembers())
{
WriteLine(3, "{0}:{1}", mi.MemberType,mi);
}
}
}
}
public static void WriteLine(Int32 indent, String format, params Object[] args)
{
Console.WriteLine(new String(' ', 3 * indent) + format , args);
}
}
public class Program
{
public static void Main()
{
/*
////通過GetAssemblies 叫用AppDomain的所有組件
foreach(Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
{
//反映當前組件資訊
//Reflector.ReflectoOnAssembly(assem);
}
////獲取當前執行的程式碼組件
Assembly a = Assembly.GetExecutingAssembly();
Reflector.ReflectOnAssembly(a);
Console.ReadLine();
*/
////獲取指定的組件
Assembly a = Assembly.LoadFrom("C15_1.dll");
Reflector.ReflectOnAssembly(a);
Console.WriteLine();
}
}
}
沒有留言:
張貼留言