Re: [問題] VS2005要如何用程式碼去加入reference
※ 引述《Dacool (大褲)》之銘言:
: ※ [本文轉錄自 C_and_CPP 看板]
: 作者: Dacool (大褲) 看板: C_and_CPP
: 標題: [問題] VS2005要如何用程式碼去加入reference
: 時間: Tue Jun 2 23:58:20 2009
: 想請問一下,有關VS2005的一些功能
: 我想用c#去寫一個小功能,就是寫一個視窗程式
: 那我點選一個按鈕,或是開啟檔案之類的功能
: 然後自己去選擇reference
: 或是程式內部自動去加入一個reference檔案到方案總管的reference資料夾裡
: 想請問一下目前VS05內建的函式庫有辦法做到這個功能嗎?
: 找了MSDN很久都找不到夠完善的方法
: by the way,有哪些地方是可以查到較多的程式資訊的?
你需要的是 late binding / reflection的功能
// Try to load a local copy of "CarLibrary.dll".
Assembly a = null;
try
{
a = Assembly.Load("CarLibrary");
}
catch(FileNotFoundException e)
{
Console.WriteLine(e.Message);
}
// Get the class type "MiniVan"
Type miniVan = a.GetType("CarLibrary.MiniVan");
// Create the Minivan object
object obj = Activator.CreateInstance(miniVan);
// Get method name "TurboBoost"
MethodInfo mi = miniVan.GetMethod("TurboBoost");
//call the method
mi.Invoke(obj, paramArray);
以上是 class & instance method 的呼叫方式
若是static method ,呼叫方式則有點不同~~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.248.161.28
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章