Effective C# 原则48:了解更多的工具和资源(译)

Effective C# 原则48:了解更多的工具和资源  
Item 48: Learn About Tools and Resources

对于C#以及.Net来说这是激动人心的时候。这些工具目前还是比较新的,整个社区都在学习如何使用这些工具。一些资源可以帮助你提高你的知识,以及为.Net和C#创建一个更大的知识社区。这些工具是我每天都向C#开发人员推荐的。关于C#实践的全部内容还在写作当中,跟进它们而且不断了解相关的内容。

第一个应该在每一个C#开发人员的工具箱的工具是NUnit, 它可以在www.nunit.org网站上找到。NUnit是一个自动进行单元测试的工具,功能和JUnit很像。和其它大多数开发人员一样,我讨厌写测试代码并且自己测试。NUnit让这些进程都变得很高效,在你有规律的使用这些工具后,可以保证你会习惯测试你所有的C#类。不管什么时候当我创建了一个类库工程时,我都会添加一个NUnit测试工程,而且把自动生成的测试做为一部分添加进来。我添加一个以创建和运行测试的配置,这样可以在每次编译时进行测试。然后,我可以转换活动的配置来控制是否要让单元测试做为正规程序的一部份存在。默认情况下,我运行它们。当我须要进行UI测试时,我会转换到另一个配置上。

在附带的使用NUnit时,你可以通过检测NUnit的源代码学到一些有意思的技术。NUnit使用一些高级的反射习惯来加载和测试你的程序集。它使用特性来查找测试包,测试用例,以及每个测试用例的期望结果(参见原则42)。这是一个非常不错的例子,可以告诉你如何使用这些技术来创建可以自己动态配置的工具,而且它可以广泛的应用。

接来下是FXCop,这是一个免费的工具,可以从GotDotNet(www.gotdotnet.com)上得到。FXCop 分析你的程序集里的IL,看它是否与实践的原则相违背,以及报告这些违例的地方。每一个原则都有一个可靠的公制规范,以及使用这一原则的原因。如本书里所有推荐的原则一样,一些文档中有一个关于某一原则的简短理由。你可以断定这些实际的问题是否遵守这些建议。同样你也可以配置是否把每一个原则都应用到项目中。我并不赞成FXCop 中的一些原则,而且我在本书前面已经说明了原因。然而,像NUnit一样,FXCop 可以成为你创建的正规程序的一部分。每次编译后,可以有一个编译后步骤,可以用FXCop 来分析你选择的原则。图6.1展示了一个从FXCop里输出的例子。尽管一些推荐并不是我喜欢的(例如有一个是让每一个程序集应该是让COM见的),但它确实是一个有用的工具,因为它让你思考很多你已经默认的决定。


图6.1,FXCop分析的一个项目:
Figure 6.1. FXCop analyzing a project.

[View full size image]

effect csharp 48.JPG


ILDasm是一个IL反汇编器,在本书不同的地方,我已经演示了一些IL代码,它们就是编译器为不同的C#结构生成的。尽管我不相信很多人会在有高级语言存在的情况下,还选择写IL代码,但你应该熟悉它。知道从不同的C#结构上生成的IL代码,可以帮助你成为一个更好的开发者。你可以为你自己的程序集检测IL代码,或者是.Net框架里的程序集。这就是使用ILDAsm,而且它是和.Net框架的SDK一起发布的。IL对于所有开发者来说都是可用的。ILDAsm可以让你看到你的程序集的中间语言。不管怎样,这是一个好的方法来学习.Net框架程序集,这也是得到的原始资料。

这些只是你正式工具箱中的一部份,但拥有这些工具只是提高你技能的一个方面。大量在线的资源以及交流社区可以让你参与和学习,以及增加你自己的C#和.net框架知识。首先也是最重要的就是GotDotNet 网站(www.gotdotnet.com),这是.Net组的官方网站。C#小组在MSDN上有一个站点,目前是在msdn.microsoft.com/vcsharp/ (它偶然在MSDN网站有变动而被重新组织)。如果你的工作主要是基于网络的,试着访问www.asp.net,这是为ASP.Net组提供的。如果你的工作主要是基于Windows Form的,试着看看www.windowsforms.net,这是Windows Form组的官方网站。这些网站包含很多常规编程的引用和实现,这些可能是你的应用程序中想要的。它们都是还源文件的组件,所以你可以检测和修改这些,让它们成为你想要的。最后也是最重要的位置应该要了解就是在MS模式和实践的网页。这个网页目前在 www.microsoft.com/resources/practices/,从这个地方,你可以查到一些常用的设计模式以及一些最好的模式的初始代码。
而且这个地方经常更新一些新的例子的代码以及库,这可能帮助你解决常规的编程问题。在写这些时,你已经可以使用10个不同的应用程序块来实现一些常规的程序要求,我确信当你阅读到这些时,这些地方已经有更多的内容了。

我还要推荐一些C#组的FAQ的订阅:http://blogs.msdn.com/csharpfaq,附带的在这个上,有几个C#组的成员用博客讨论一些C#问题。你可以在这里找到最新的列表: http://msdn.microsoft.com/vcsharp/team/blogs/

如果你学习更多的而且对语言和环境想得到更深入的了解,你可以检测共享的CLI(code-named rotor)。这包含.net框架以及C#编译器的一些核心内容。你可阅读这些资料来对C#语言的每一个功能和.Net框架得到更深入的理解。并不是所有的.net商业框架都有可用的共享资料:例如,特殊的Windows代码并没有发布共享代码。然而,这些已经发布了的子集,同样够你学习更多的关于CLR和C#语言内部的东西。

C#编译器已经和共享的CLI资料一起发布,这是用C++写的,它做为底层的CLR代码存在。你须要对C++有很深的背景知识,以及对编译器设计有清楚的认识才能很好的理解它。现代的语言编译器是复杂的软件块,但CLR资料是一个有用的工具,来理解.Net框架的核心功能是如何实现的。

这里只是给出了一个简单的列表, 我只是在众多资料中介绍了一个表面。很多资料你都可以多MS上得到,或者其它在线网站,或者是书。你越是多的使用这些工具,你就可以得到越多的知识。整个.Net以及C#社区是在前进的,因为它发展的很快,这些列出的资源也可能不断的在改变。你可以自己学习和自己写稿。

============================
   

Item 48: Learn About Tools and Resources
These are exciting times for C# and .NET. These tools are still new enough that the entire community is learning how best to use them. Several resources are available to help you improve your knowledge and build a larger community of knowledge for .NET and C#. These are the tools that I use daily and recommend to other C# developers. The full set of C# best practices is still being written. Keep up, and get involved.

The first tool that should be in every C# developer's toolbox is NUnit, available on the web at www.nunit.org. NUnit is an automated unit-test tool, functionally similar to JUnit. Like most developers, I hate writing tests and testing my code. NUnit makes that process so efficient that using it regularly ensures that you will be in the habit of testing all your C# classes. Whenever I make a class library project, I add an NUnit test project and include executing the tests as part of the automated build. I add new configurations that include build and test, which run the tests on every compile. Then I can switch the active configuration to control whether unit tests are run as part of the regular build process. By default, I run them. I switch to the other configuration when I'm running tests that require the UI.

In addition to using NUnit, you can learn several interesting techniques by examining the NUnit source code. NUnit uses some advanced reflection idioms to load and test your assemblies. It uses attributes to find test suites, test cases, and expected results from each test case (see Item 42). It's a great example of how to use these techniques to build a tool that configures itself dynamically, and it can be used in a wide variety of ways.

Next is FXCop, a free tool available at GotDotNet (www.gotdotnet.com). FXCop analyzes the IL in your assembly against a set of rules and best practices, and reports violations. Each rule has a reliability metric and a reason for the rule. As with all the recommendations in this book, the rule documentation has a brief justification for the advice. You can then determine whether the advice fits your particular problem space. You can also configure whether each rule is applied in your project. I disagree with some of the FXCop rules, and I've said as much earlier in this book. However, like NUnit, FXCop can become part of your regular build process. Each build can have a post-build step that analyzes the code using FXCop with your chosen rules. Figure 6.1 shows a sample output from FXCop. Although some of the recommendations are not to my liking (such as the one that every assembly should be COM visible), it's a useful tool because it makes you think about many decisions you might have made by default.


Figure 6.1. FXCop analyzing a project.

[View full size image]

effect csharp 48.JPG

 

IldAsm is an IL disassembler. In different locations in this book, I've shown the IL that the compiler generates for different C# constructs. Although I don't believe that many people are choosing to write IL in favor of any high-level language, you should be familiar with it. Knowing the IL that gets generated from different C# constructs will help you be a better developer. You can examine the IL for your own assemblies or for assemblies in the .NET Framework by using IldAsm, which comes with the .NET Framework SDK. The IL is available to all developers. IldAsm lets you see the intermediate language for your assemblies. However, a better way to learn about the .NET Framework assemblies you use is to get the source.

Those are the tools that are part of your regular toolbox. But having the tools is only one way to improve your skill. A variety of online resources and communities enables you to participate and learn and increase your knowledge of C# and the .NET Framework. First and foremost is the GotDotNet site (www.gotdotnet.com), the official site of the .NET team. The C# team has a page on the MSDN site, currently located at msdn.microsoft.com/vcsharp/ (it moves occasionally as the MSDN site gets reorganized). If your work is primarily web-based, try www.asp.net, the site for the ASP.NET team. If your work is Windows Formsbased, try www.windowsforms.net, the official site of the Windows forms team. These sites contain reference implementations of many common idioms that you will want to make use of in your applications. They all come with source components, so you can examine and modify them as you need to for your purposes. The last and most important location to become familiar with is the MS Patterns & Practices page. This page is currently located at www.microsoft.com/resources/practices/. From this location, you will find common patterns and starter code for those best practices. This area continues to be updated with more sample code and libraries that will help you solve common programming problems. At this writing, you can use 10 different application blocks to implement common programming requirements; I'm sure there are already more by the time you read this.

I also recommend subscribing to the C# Team FAQ: http://blogs.msdn.com/csharpfaq. In addition to that one, several of the C# team members have blogs where they discuss C# issues. You can find the up-to-date list at http://msdn.microsoft.com/vcsharp/team/blogs/.

If you want to learn more and get an even deeper understanding of the language and the environment, examine the shared source CLI (code-named rotor). This includes the core .NET Framework and a C# compiler. You can read the source code to gain an even deeper understanding of each feature in the C# language and the .NET Framework. Not every assembly in the commercial .NET Framework is available in the shared source version: For example, the Windows-specific code is not delivered with the shared source code. However, what is delivered is a rich subset that you can use to learn much about the inner workings of the CLR and the C# language.

The C# compiler delivered with the shared source CLI is written in C++, as is part of the low-level CLR code. You need to have a strong background in C++ and a strong understanding of compiler design to understand it thoroughly. Modern-language compilers are intricate pieces of software, but the CLR source is a valuable tool to understand how the core features in the .NET Framework are implemented.

This is intentionally a small list. I've only touched the surface of the many resources that are available to you from Microsoft, online at other sites, and in books. The more you use these tools, the more knowledgeable you will be. The entire C# and .NET community is moving forward. Because it's moving forward quickly, the list of resources changes constantly. Learn and contribute yourself.

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/549855.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

计算机2013知识,【2013年计算机基础知识习题与答案(三)】- 环球网校

46.与十进制数128等值的二进制数是10000000.47.与十进制数217等值的二进制数是11011001.48.八进制数的基数为8,能用到的数字符号个数为8.49.十进制数38转换成八进制数是46.50.十进制数72转换成八进制数是110.51.与十进制数283等值的十六进制数是11B.52.与二进制数11…

上周回顾:艾妮闹春 Sun/HP高层人士震荡

进入4月,春暖花开。然而随着Vista首个漏洞“ANI”的到来,上周显然让许多人又紧张了一回。同样紧张的还有IT媒体的记者:周一一上班就传出Sun公司大中华区总裁余宏德和其他高管离职的消息,周五临下班HP中国总裁孙振耀又宣布“退休”…

计算机自带游戏如何删除,详细教你系统怎么删除游戏

很多时候,在我们安装系统就会自带一些游戏软件,但是我们不怎么感兴趣,放在那里有占用内存,只有将它们删除了,如何彻底删除windows系统自带的游戏蜘蛛纸牌呢?下面,就有系统之家小编来给大家讲解系…

C#中的函数参数能不能有默认值的解决方法

C#不支持参数默认值,如果要实现相同功能,可以使用函数重载的方法模拟实现。 如: void MsgBox(string msg, string title) { MessageBox.Show(msg, title); } void MsgBox(string …

平均曲率的近似计算 计算机中

简介 平均曲率,在图形学处理的过程中,应用很广泛。 参考链接 图形学论坛 论文:Laplacian Mesh Optimization数学表示 公式 平均曲率向量 latex 表示 $$\bar{k}{i}n{i} \frac{1}{4A_{i}}\sum_{{i,j}\in{E}}(\cot{\alpha} \cot{\beta})(v_j -…

win10创建新的计算机用户名和密码错误,Win10开机提示用户名或密码不正确现象的解决办法...

有用户遇到Win10开机提示用户名或密码不正确的问题,当你点击“确定(OK)”后欢迎屏幕上会出现两个相同的用户账户让你选择,让你不知道该选择哪一个,这个问题是什么原因?怎么解决呢。问题原因出现上述问题的原因可能是你在设置了Win…

让UpdatePanel支持文件上传(4):数据传输与解析机制

现在就要开始整个项目中最有技巧的部分了。如果我们的组件需要在多种浏览器中正常的运行,我们必须好好考虑一下发送和解析数据的方式。如果我们把这部分的机制完全交给ASP.NET AJAX原有的行为来执行,则会遇到问题。下面的代码片断就是IE 7和FireFox在收到…

删除计算机360云盘,win7系统怎么取消电脑右键保存到360云盘选项

在日常使用win7系统的时候,我们经常会用到右键菜单,可是有时候会遇到一些没有用的选项,比如保存到360云盘选项,如果不喜欢的话,要怎么取消电脑右键保存到360云盘选项呢?具体步骤如下。1、首先有这一项的都是…

Unity3D笔记十五 碰撞、移动

碰撞 Collision. [kəˈliʒən] 碰撞;冲突;(意见,看法)的抵触;(政党等的)倾轧 选择一个需要添加碰撞器的游戏对象后 Component->Physics- Unity一共为对象提供了6 种碰撞器&…

网吧服务器RAID 0+1硬盘阵列组建图解

网吧服务器RAID 01硬盘阵列组建图解步小羽   2007年04月13日   来源:天下网吧联盟随着网吧规模扩大,网吧电脑数量也会相应增加,上网的顾客也随之增多,服务器硬盘数据存取的速度将会成为新的瓶颈,很多顾客开始投诉服务…

大工17秋《计算机文化基础》在线测试1,奥鹏大工15秋《计算机文化基础》在线测试1答案...

一、单选题(共 10 道试题,共 50 分。)V1. 二进制数11111010所对应的十进制数是( )。A. 250B. 252C. 253D. 255满分:5 分2. 在计算机领域中,( )通常用英文单词“byte”来表示。A. 字B. 中央处理器C. 字节D. 位满分:5 分3. 下列…

VXLAN实验

拓扑图: SPINE配置: hostname SPINE-1vdc SPINE-1 id 1 limit-resource vlan minimum 16 maximum 4094 limit-resource vrf minimum 2 maximum 4096 limit-resource port-channel minimum 0 maximum 511 limit-resource u4route-mem minimum 248 maximum…

终于开始工作了

在来到上海的 第三周我开始了我的第一天的工作,今天的主要任务是看老大给的资料,看了一天,下班的时候居然还下着雨,又没拿伞,只有被浇了,呵呵,可怜了我姐姐送我的880的西服。如果让她老人家知道…

桂林电子科技大学计算机专业排名,桂林电子科技大学专业排名怎样

桂林电子科技大学专业排名怎样桂林电子科技大学是工业和信息化部与广西壮族自治区共建高校、广西壮族自治区重点建设高校。小编整理了关于桂林电子科技大学专业之间的排名,希望对大家有帮助!桂林电子科技大学专业排名情况1、 通信工程 推荐指数: 4.8(156人推荐)2、 …

Ubuntu使用记录

经一个朋友推荐决定使用Ubunta,主要被他说的,对个人Destop使用非常方便,所吸引网上被评价为最受个人用户青睐的Linuxhttp://distrowatch.com/排名据说第一漂亮的界面+强大的资源支持了解Ubuntuubuntu8.04光盘安装图文指南 分区设置…

VSTS For Testers读书笔记(5)

四、编辑WebTest3、添加提取规则和自定义提取规则添加提取规则1、当必须从特定页中捕获一部分数据并且供另一个页使用时,就需要用到提取规则。可以使用提取规则从响应中复制字符串,然后将字符串存储到上下文变量中,以供任何后续请求使用。通过…

html里面怎么ul加高度,div里面嵌套了ul,为什么div的高度小于ul高度

div高度见阴影部分ul高度见阴影部分实现的html代码如下:热门推荐css代码如下:.navBar {clear: both;width: 100%;border: solid;/*border-top: solid;*/border-bottom: solid;border-width: 1px;border-color: #dddddd;margin:0px;height: 1.5em;}.navBa…

Eclipse 插件开发中的 classnotfound 问题 zz

目的:Eclipse插件开发中,经常要引用第三方包或者是引用其他插件中的类,由于插件开发环境引用类路径的设置和运行平台引用类路径的设置不同,经常导致开发过程OK,一旦运行则出现NoClassDefFoundError的问题。本文的目的是…

Asp.net2.0水晶报表的一些示例源码

最近关注了一下Asp.net2.0中水晶报表的资料,发现示例少之又少(怀疑是水晶报表免费的比较少的缘故),搜集到了Asp.net官方的许多示例源码,试了几个还不错,这里发给大家分享一下(我仅把Asp.net C#部…

SP2中修复IE浏览器的一些技巧

点击链接但没有反应;在开始菜单的运行对话空中输入URL,但不能弹出IE窗口。以上仅是用户所遇的众多问题中的两种。人们处理该问题的一个简单方法就是重新安装IE.它也确实有用,但你会发现重新安装IE对于这个较简单的问题到显得小题大做了。IE的许多这类问题…