|
|
Reflection
Chap4_Ex18.cs
using System;
using System.Reflection;
public class TestReflection {
public void WithoutParameters() { }
public bool WithParameters(string p1) { return true; }
}
public class MethodInformation {
public static void Reflect(MethodInfo mi) {
Console.WriteLine("-------------------------------");
Console.WriteLine("reflecting method:{0}",mi.Name);
Console.WriteLine("parameters:");
foreach(ParameterInfo pi in mi.GetParameters())
Console.WriteLine("\t{0}, type:{1}",pi.Name, pi.ParameterType);
// etc ...
}
public static void Main(string[] args) {
Assembly a = Assembly.LoadFrom("TestReflection.dll");
Type t = a.GetType("TestReflection");
MethodInfo mi = t.GetMethod("WithoutParameters");
MethodInfo mi2 = t.GetMethod("WithParameters");
Reflect(mi);
Reflect(mi2);
}
}
|
|