class Program
{
static void Main(string[] args)
{
//Console.WriteLine(Untity.Rollover(Console.ReadLine()));
//Console.WriteLine(Untity.make('w', 5));
//foreach (string s in Untity.GetStringArray(Console.ReadLine()))
//{
// Console.WriteLine(s);
//}
Assembly ass = Assembly.LoadFile(@"E:\360data\重要資料\我的文件\visual studio 2010\Projects\dll\lrbrary\bin\Debug\lrbrary.dll");//載入程式集
Type type = ass.GetType("lrbrary.Untity");//命名空間.類 。執行個體化 命名空間和類的名字必須一起指定
FieldInfo[] fields = type.GetFields();//擷取欄位
PropertyInfo[] propertys = type.GetProperties();//擷取屬性
MethodInfo[] methods = type.GetMethods();//擷取方法
foreach (MethodInfo method in methods)
{
Console.WriteLine("方法名稱:" + method.Name);
Console.WriteLine("參數個數:" + method.GetParameters().Length);
foreach (ParameterInfo param in method.GetParameters())
{
Console.WriteLine(param.ParameterType + ":" + param.Name);
}
}
object obj = ass.CreateInstance("lrbrary.untity", true);
MethodInfo meth = methods[2];//調用方法
Console.WriteLine(meth.Invoke(obj, new object[] { }));//我們想用的方法是一個靜態方法,這時候Invoke的時候,對於第一個參數是無視的,也就是我們寫什麼都不會被調用,即使我們隨便new了一個any這樣的Object,當然這種寫法是不推薦的。但是我們如果Invoke的時候用了類型不一致的執行個體來做為參數的話,將會導致一個運行時的錯誤。
//Console.WriteLine(meth.Invoke(null, null));//調用無參數靜態方法的例子,這時候兩個參數我們都不需要指定,用null就可以了。
Console.ReadKey();
}
}