標籤:des winform style blog http io os 使用 ar
上周為了快速瞭解一個.NET的庫而需要查看其類型層次。假如要在文章中表示一個類型層次,還是用文本比較舒服,始終是不方便。Reflector雖然能夠顯示類型層次,但我無法方便的把顯示出來的類型層次轉換為文本形式。而且,Reflector在顯示基類和衍生類別的時候都會使用類型的全名,但有時候我只需要看到類型的簡單名字。我也找過另外幾個工具,例如.NET Framework SDK以前內建的Windows 表單類查看器(Wincv.exe),但它只顯示類型自身的資訊以及基類的資訊,而不顯示衍生類別的資訊,還是不夠用。
沒找到現成合用的工具,只好自己寫一個了。於是就用C#/WinForms寫了一個簡單的GUI程式,只是用來顯示類型層次資訊,並且能把類型層次以文本形式複製到剪貼簿。
一張:
對應這張得到的文本表示:
Java代碼
- IList<T>
- Collection<T>
- KeyedCollection<TKey, TItem>
- List<T>
- ReadOnlyCollection<T>
===========================================================================
開源形式:
該程式採用MIT形式的許可證開放原始碼。程式與源碼可在本帖附件的壓縮包中獲得。
運行環境:
由於使用了LINQ,這個程式需要.NET Framework
3.5才能正常運行。如果需要移植到.NET Framework 2.0的話,可以使用Mono的System.Core.dll的實現。
===========================================================================
使用方法:
可以從命令列提供參數來開啟assembly,格式為:
ClassHierarchyViewer <assembly-path>
或者直接啟動程式,並通過以下三種方式的任意一種來開啟assembly:
1、在文字框中輸入assembly的完整名稱(Name,Version,Culture,PublicKeyToken),並按斷行符號或點擊“Load By Name”按鈕;
2、按“Open File...”按鈕通過對話方塊選取assembly;
3、從檔案瀏覽器把assembly拖放到該程式的視窗裡。
同一時間只會有一個assembly顯示在視窗中。
其它功能應該不言而喻了,我就直接把readme檔案的內容帖出來吧:
引用////////////////////////////////////////////////////////////////
Name: ClassHierarchyViewer
Author: RednaxelaFX (Kris Mok, [email protected])
Version: 0.3.0.1
Release Date: 2008-09-23
License: MIT style license. See License.txt.
////////////////////////////////////////////////////////////////
Description:
A simple tool that shows the class hierarchy within a given
.NET assembly.
Required Environment:
Windows XP or Vista, with .NET Framework 3.5 or above installed.
////////////////////////////////////////////////////////////////
Usage:
1. Start program from command line:
usage: ClassHierarchyViewer <assembly-path>
- or -
2. Start program from GUI:
Assemblies can be loaded by one of:
* enter the assembly‘s full name in the combobox, then click
"Load By Name" button;
* enter the assembly‘s full name in the combobox, and hit
Enter;
* Click "Open File..." button, and choose an assembly file;
* Drag and drop a assembly file from Explorer.
Only one assembly is active at a time.
A few commonly used BCL assemblies‘ names are added to the
combox already, including:
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.AddIn, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac
System.Net, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
////////////////////////////////////////////////////////////////
Functions:
The GUI window is divided into 3 major components:
1. Class List Window (on the left)
Displays all types (except "<Module>") in the given assembly,
grouped by their namespaces, sorted by the type‘s name.
Types that are not visible outside the assembly are marked gray.
2. Class Hierarchy Window (on the upper right)
When a type is selected in the Class List Window, its type
hierarchy will be shown in this window.
The hierarchy shown includes the type itself, its base type (up
to System.Object), and all its derived types.
Checking/unchecking the "Full Name" checkbox will cause this
window to reload, showing types with their simple name/full name.
Clicking "Copy to Clipboard" button will copy the type hierarchy
to the clipboard, in text representaion.
3. Class Member Window (on the lower right)
When a type is selected in the Class Hierarchy Window, its
members will be shown in this window. This does not include
a type‘s nested types.
Checking/unchecking the "Use Alias" checkbox will cause this
window to reload, showing types with their alias/name.
////////////////////////////////////////////////////////////////
Known Issues:
1. TreeViews flicker when mouse moves over them rapidly.
Haven‘t found any solution to this, maybe that‘s just how
WinForms behaves.
2. Copying the type hierarchy causes flickering.
This is because of the way data is loaded: derived types are
added onto the tree when a node is expanded. To make sure
derived types are added correctly, the whole tree is expanded
before its text representation can be gathered. This will be
improved in later versions with M-V-VM pattern.
3. Properties‘ getter and setter methods aren‘t associated with
the properties‘ nodes.
Due to the lack of developing time, certain useful functions
such as this one is not implemented yet. Will be fixed in
later versions.
4. Doesn‘t show what interfaces a type implements.
Same as above. Will be fixed.
5. Cannot load an assembly from GAC just by browsing in the open
file dialog.
I know. That‘s why there‘s an alternative, to load assemblies
with their full names. Later on I might add a dialog to select
assemblies from GAC.
////////////////////////////////////////////////////////////////
Note:
The icons used in this program originated from Microsoft Visual
Studio 2008‘s image libraries, Visual Studio Image Library:
24bit Objects and Objects (WinVista style, .png).
許可證:
引用The MIT License
Copyright (c) 2008 RednaxelaFX (Kris Mok, [email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
現在這個簡陋的程式最大的限制就是無法自如的開啟GAC裡的assembly,因為在Windows上安裝.NET Framework之後,GAC目錄預設會被Fusion管理起來,需要通過修改註冊表來禁用這個功能才能看到GAC裡的assembly的路徑。當然,我可以掃描%WINDOWS%\Assembly\下的所有assembly,不過這個功能還沒做進來;別的類似程式在掃描GAC時非常慢,所以我不太肯定要不要把這個功能做進來。現在通過強式名稱一樣能開啟GAC裡的assembly,只是使用者會辛苦一點了。預先放在文字框的下拉式清單裡的名稱應該能滿足一般使用需要了吧。
如果有什麼意見和建議,歡迎提出。有需要請通過站內簡訊或者電子郵件聯絡,謝謝 ^ ^
- ClassHierarchyViewer_0.3.zip (1 MB)
- ClassHierarchyViewer_0.3.0.1.zip (1 MB)
.NET的類型層次查看工具