惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
博客园 - 聂微东
小众软件
小众软件
J
Java Code Geeks
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
量子位
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
月光博客
月光博客
B
Blog RSS Feed
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
I
Intezer
The Register - Security
The Register - Security
博客园 - 【当耐特】
博客园 - 司徒正美
L
Lohrmann on Cybersecurity
U
Unit 42
N
News and Events Feed by Topic
S
Security Affairs
V
Visual Studio Blog
Y
Y Combinator Blog
Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
大猫的无限游戏
大猫的无限游戏
S
Schneier on Security
P
Privacy International News Feed
TaoSecurity Blog
TaoSecurity Blog
Spread Privacy
Spread Privacy
G
Google Developers Blog
NISL@THU
NISL@THU
Project Zero
Project Zero
P
Palo Alto Networks Blog
Help Net Security
Help Net Security
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
S
Security @ Cisco Blogs
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - 秋枫

使用BizTalk Server常见问题处理 BizTalk Server中简单xml架构使用举例 CodeProject.com上微软BizTalk平台技术文章集锦 BizTalk Server 2006中使用MQSeries适配器问题处理 基于.Net平台应用程序唯一运行实例实现 使用BizTalk Server的Sql适配器出现“新事务不能登记到指定的事务处理器中”异常的处理 谈基于.net平台windows开发中的模式窗体 Visual studio 2005下xml的xsl转换调试 小提国内一些提供RSS服务的网站生成Rss文件问题 Visual studio .net 的“隐蔽性”和容易“忽略”的功能 使用sqlcmd(osql) 实用工具列出本地网内的Sql Server 服务器 《敏捷注册表》1.0使用说明书 《敏捷注册表》1.0概述 使用从BindingManagerBase.PositionChanged 事件的注意点 使用Microsoft SQL Server 2000的XML查询 asp.net中显示DataGrid控件列序号的几种方法 使用.net framewrok 1.1版System.Windows.Forms.TreeView的一个问题 使用.net framewrok 1.1版注册表API的局限和解决 使用SaveFileDialog需要注意的情况
使用.net framework中常用类在2.0版中的新功能
秋枫 · 2005-08-06 · via 博客园 - 秋枫

郑佐 2005-8-6

在上一篇《浏览.NET Framework 2.0 类型库中新增的常用功能》一文中我主要列了几个新增的常用主件,本文作为小结主要针对一些常用类的扩展来讲最近在使用C# 2.0 的时候发现的几个新特征,讲得不当之处请网友指正。

1Exception异常基类

2.0下,Exception基类增加了Data属性,原型如下,

public virtual IDictionary Data {get;}

可见其实现了IDictionary接口,用来存储异常的自定义信息,由此想到在ExceptionManagement block中通过继承增加NameValueCollection类成员来使BaseApplicationException具有该项功能,Exception新增Data属性的灵感来源于此?

2File增加解密加密功能

使用File的新增加密解密方法来保护文件。在windows2003系统窗口的文件夹选项菜单的查看选项卡中选中用彩色显示加密或压缩的NTFS文件复选框(在xp2000系统里应该也有相关的选项)就可以看到被加密的文件颜色会不一样。

具体方法定义如下,

public static void Encrypt(     string  path ); //加密

public static void Decrypt(    string  path );//解密

加密后,文件就会变成绿色,如果该文件没有授权给其他用户,那在其他用户登录时就无法访问该文件。点击加密文件属性可以得到加密的更多信息。

3DriveInfo

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也可以实现上述所有功能。

4System.Windows.Forms.Menu

2.0中增加了Tag属性,这样从它继承的MenuItem也就包含了该属性,就像TreeNode.Tag属性可以保存各种对象。

5Console类明显得到增强

Consle增加了很多功能,包括设置控制台窗体的外观大小和颜色,还可以设置、移动里面的光标,设置缓冲区,判断键盘的那些特定键是否开启等等。举个例子像Console.ReadKey ()以及它的重载方法将会很有用。

以上特征是我针对.net framework 2.0 Beta 2来写的,在正式版出来后也许会有些改动。

posted on 2005-08-06 20:31  秋枫  阅读(1016)  评论()    收藏  举报