.NET Framework 2.0特征詳細使用說明手冊
.NET Framework 2.0的發布為開發人員提供了許多新的功能。我們在這里就會為大家詳細介紹一下.NET Framework 2.0特征的使用方法,希望能幫助大家方便理解.NET Framework 2.0版本中的性能。#t#
.NET Framework 2.0特征1.Exception異常基類
在2.0下,Exception基類增加了Data屬性,原型如下,
public virtual IDictionary Data {get;}
可見其實現了IDictionary接口,用來存儲異常的自定義信息,由此想到在ExceptionManagement block中通過繼承增加NameValueCollection類成員來使BaseApplicationException具有該項功能,Exception新增Data屬性的靈感來源于此?
.NET Framework 2.0特征2.File增加解密加密功能
使用File的新增加密解密方法來保護文件。在windows2003系統窗口的文件夾選項菜單的查看選項卡中選中用彩色顯示加密或壓縮的NTFS文件復選框(在xp或2000系統里應該也有相關的選項)就可以看到被加密的文件顏色會不一樣。
具體方法定義如下,
public static void Encrypt( string path ); //加密
public static void Decrypt( string path );//解密
加密后,文件就會變成綠色,如果該文件沒有授權給其他用戶,那在其他用戶登錄時就無法訪問該文件。點擊加密文件屬性可以得到加密的更多信息。
.NET Framework 2.0特征3.DriveInfo類
DriveInfo類提供系統驅動器的信息,是.net 2.0下新增的類,可以通過
DriveInfo[] drivers = DriveInfo.GetDrives();
得到驅動信息,如:
AvailableFreeSpace
Indicates the amount of available free space on a drive.(磁盤配額考慮在內)
DriveFormat
Gets the name of the file system, such as NTFS or FAT32.
DriveType
Gets the drive type.
IsReady
Gets information on whether or not the drive is ready.
Name
Gets the name of the drive.
RootDirectory
Gets the root directory of the drive.
TotalFreeSpace
Gets the total amount of free space available on a drive.
TotalSize
Gets the total size of storage space on the drive.
VolumeLabel
Gets and sets the volume label of the drive.
上面的VolumeLabel是可讀寫的,其他屬性是只讀的。在使用時一般需先判斷IsReady屬性是否為True,如果沒有準備好,那訪問其他屬性就會發生異常,還有需要注意在編程時是否有權限訪問。
DriveType枚舉也是在.net 2.0下新增的,
Member name
Description
CDRom
The drive is a CD ROM device.
Fixed
The drive is a fixed disk.(固定磁盤驅動器)
Network
The drive is a network drive.(網絡驅動器)
NoRootDirectory
The drive does not have a root directory.(不含根目錄的驅動器)
Ram
The drive is a RAM disk.(RAM閃存)
Removable
The drive is a removable storage device.(可移動存儲設備)
Unknown
The type of drive is unknown.(未知設備類型)
在1.1版中使用Directory.GetLogicalDrives();來得到驅動器。當然使用WMI也可以實現上述所有功能。
.NET Framework 2.0特征4.System.Windows.Forms.Menu類
在2.0中增加了Tag屬性,這樣從它繼承的MenuItem也就包含了該屬性,就像TreeNode.Tag屬性可以保存各種對象。
.NET Framework 2.0特征5.Console類明顯得到增強
Consle增加了很多功能,包括設置控制臺窗體的外觀大小和顏色,還可以設置、移動里面的光標,設置緩沖區,判斷鍵盤的那些特定鍵是否開啟等等。舉個例子像Console.ReadKey ()以及它的重載方法將會很有用。
以上特征是我針對.net framework 2.0 Beta 2來寫的,在正式版出來后也許會有些改動。