2011-08-04 68 views
0

一個應用程序,我想開發如Visual Studio對象瀏覽器的應用程序,即用戶將輸入類似System.Text命名空間或系統類。點擊按鈕後,我們必須找出「System.Text」中的所有類,函數,屬性等。創建如Visual Studio對象瀏覽器

我嘗試以下,但失敗了。

 Assembly SampleAssembly; 
     SampleAssembly = Assembly.Load("System.Text"); 

     Type[] Types = SampleAssembly.GetTypes(); 
     // Display all the types contained in the specified assembly. 
     StringBuilder str = new StringBuilder(); 

     foreach (Type oType in Types) 
     { 
      str.Append(oType.Name.ToString() + "</br>"); 
     } 
     divAsseblyData.InnerHtml = str.ToString(); 
+0

您是否遇到異常? –

+0

是的,得到錯誤FileNotFound異常?第2行:SampleAssembly = Assembly.Load(「System.Text」); – Justinonday

+1

沒有像'System.Text'程序集這樣的東西;它只是mscorlib.dll中的一個命名空間。重寫代碼以加載mscorlib,然後導航到System.Text命名空間。 –

回答

2

'System.Text'是一個命名空間而不是程序集,所以我假設你想加載程序集'System'。

不同,需要通過裝配的全名字符串參數使用Assembly.Load()。

要獲得完全合格的名稱,你可以做這樣的事情:

Assembly SampleAssembly; 
SampleAssembly = Assembly.Load(typeof(System.Activator).Assembly.FullName); 
// get the type of some random object in the assembly (Activator) and then 
// call .Assembly.FullName which returns the fully qualified name of the assembly 

或者你也可以按 + [R,鍵入「集結號」並回車,然後右鍵單擊 - 上>禮儀你在代碼的格式需要和手動設置禮儀大會:

「mscorlib程序,版本= 2.0.0.0,文化=中性公鑰= b77a5c561934e089」

SampleAssembly = Assembly.Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); 
+0

這是一個查找程序集名稱的棒極了! – Jacob

+0

好的,非常感謝你Razan Panda先生。你可以分享下一步該怎麼做。!ie在mscorlib.dll中如何導航System.Text或System.Web? – Justinonday

+0

@Justin:你是什麼意思導航?你需要做什麼? –

相關問題