namespace ReflectionType
{
public class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("列出程序集中所有類");
Assembly Ably = Assembly.LoadFrom("ReflectionType.exe");
Type[] tps = Ably.GetTypes();
foreach (Type tp in tps)
{
Console.WriteLine(tp.Name);
}
Console.WriteLine("列出HelloWord中的所有方法");
Type tpHelloWord = typeof(HelloWord);
MethodInfo[] mInfos = tpHelloWord.GetMethods();
foreach (MethodInfo mInfo in mInfos)
{
Console.WriteLine(mInfo.Name);
}
Console.WriteLine("列出HelloWord中的所有屬性");
PropertyInfo[] pInfos = tpHelloWord.GetPropertIEs();
foreach (PropertyInfo pInfo in pInfos)
{
Console.WriteLine(pInfo.Name);
}
Console.WriteLine("實例化Hello Word,並調用HelloWord方法");
Object obj = Activator.CreateInstance(tpHelloWord);
string[] sArray ={ "GMRBrian" };
Object objName = Activator.CreateInstance(tpHelloWord, sArray);
MethodInfo mSayHello = tpHelloWord.GetMethod("SayHello");
mSayHello.Invoke(obj, null);
mSayHello.Invoke(objName, null);
Console.ReadLine();
}
}
}