Effective C#之Item 48:Learn About Tools and Resources

  rel="File-List" href="file:///C:%5CDOCUME%7E1%5CHelios%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"> rel="Edit-Time-Data" href="file:///C:%5CDOCUME%7E1%5CHelios%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_editdata.mso"> rel="themeData" href="file:///C:%5CDOCUME%7E1%5CHelios%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"> rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5CHelios%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml">

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.

对于C#.NET来说这都是值得高兴的时刻。这些工具还很新,整个社区正在学习如何更好的利用它们。一些资源对于帮助你提高认知,构建关于.NETC#的更大的知识社区是很有用的。这些工具是我每天都在用的,推荐给其他C#开发者。C#最好实践的完整集合还在编写中。跟上,走进来。

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.

第一个应该在每个C#开发者的工具箱里面的工具应该是NUnit,可以由www.nunit.org获得。NUnit是一个自动单元测试工具,功能上和JUnit相似。像多数开发者一样,我痛恨编写测试,并测试自己的代码。NUnit使得该过程很高效,经常使用它可以保证你养成测试所有C#类的习惯。当我创建一个类库项目时,我都添加一个NUnit测试项目,而且要执行作为自动编译一部分的测试。我添加新配置,包含编译和测试,每次编译时都运行测试。然后我转换活动的配置来控制是否让测试作为通常的编译过程的一部分而存在。默认情况下,我运行它们。当我运行需要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.

对于使用NUnit,还有,通过检测NUnit源代码,你可以学到一些有趣的技巧。NUnit使用一些高级的反射习惯来加载并测试程序集。它使用特性来寻找测试包,测试用例,以及每个测试用例的期望结果(Item42)。这是如何使用这些技术来构建动态配置自己的工具的很好的例子,它能够被用在很广阔的方面。

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.

接下来是FXCop,是一个免费的工具,你可以在GotDotNet (www.gotdotnet.com)获得。FXCop使用一系列规则和最好的实践来分析你的程序集里面的IL。每个规则都有可信赖的度量和原因。和本书中的其它建议一样,规则文档对该建议有主要的判断标准。然后你可以决定该建议是否符合你的特定问题空间。你也可以配置每个规则是否应该用于你的项目。我不同意FXCop的一些规则,在本书的很早时候我就说过。然而,像NUnit一样,FXCop可以成为你的常规编译程序的一部分。每次编译有快速编译的步骤,可以使用FXCop根据选定的规则来分析代码。Figure6.1展示了一个FXCop的输出例子。虽然一些建议不符合我的喜好(例如,每个程序集样该是COM可见的),它是可用的工具,因为它会让你考虑很多你可能已经默认做的决定。

Figure 6.1. FXCop analyzing a project.

6.1 FXCop分析一个项目

 

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.

IldAsmIL反编译器。在本书的不同地方,我已经展示了编译器为不同的C#结构体生成的IL。虽然我不相信很多人选择利用任何高层次语言编写IL,但是你应该要熟悉它。了解由不同C#结构体生成的IL会帮助你成为更好的开发者。你可以使用IldAsm来检测自己的程序集或者.NET框架里的程序集,IldAsm是和.NET框架SDK一齐发布的。IL对于任何开发者都是可用的。IldAsm让你看到程序集的中间语言。然而,学习你使用的.NET框架程序集的更好的方法是获得源代码。

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 Forms based, 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.

这些是你的常规工具箱的一部分,但是有这些工具只是提高你技巧的一种方式。一系列在线资源和社团让你加入,对C#.NET框架的知识进行学习并提升。首先是GotDotNet站点(www.gotdotnet.com)NET团队的官方站点。C#团队在MSDN站点也有一个页面,当前是msdn.microsoft.com/vcsharp/ (MSDN站点被重新组织时,它会被随机的移动)。如果你的工作主要是基于web的,尝试ASP.NET团队的站点www.asp.net。如果你的工作是基于Windows窗体的,尝试www.windowsforms.net,是Windows窗体团队的官方站带你。这些站点包含了很多常见习惯的参考实现,在你的应用程序里面你很可能要利用到。它们都是源代码组件的形式,因此你可以为了自己的目的来检查并进行修改。最后一个,也是最重要的地方是微软的Patterns & Practices页面。该页面当前在www.microsoft.com/resources/practices/。从这个地方,你将找到常见的模式和这些最好实践的起始代码。该领域继续更新更多的样例代码和库,将帮助你解决常见的编程问题。在编写这的时候,你可以使用10个不同的应用程序块来实现常见的编程要求;在你读到这些的时候,我可以肯定已经有了更多。

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/.

我同时推荐订阅C#团队的FAQhttp://blogs.msdn.com/csharpfaq。除了那个,C#团队的一些成员都有博客,它们在那里讨论C#问题。你可以在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.

如果你想学到更多,对语言和环境理解的更深入,那么检查共享资源CLI(code-named rotor),包括核心.NET框架和C#编译器。你可以阅读源代码,对C#语言和.NET框架的每个特性获得更深入的理解。不是所有在商业.NET框架里的所有程序集在共享源版本里面都可用:例如,和Windows相关的代码都不和共享源代码一起发布。然而,发布的这些已经是很丰富的子集了,你可以使用它们来学习CLRC#语言的内部工作。

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.

随着共享源码CLI发布的C#编译器是由C++编写的,是底层CLR代码的一部分。你需要有很强的C++背景以及对编译器设计很强的理解,才能彻底的理解。现代语言编译器是软件的复杂部分,但是CLR源码对理解.NET框架中的核心特性是如何实现的是很有价值的工具。

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.

这是特意精简过的小列表。我只是在很多可用资料里面接触了一些皮毛,从MS,到其它在线网站,或者是书。你越是多的使用这些工具,就可以得到越多的知识。整个C#.Net社区是在发展的,因为它发展的很快,这些列出的资源在不断的改变。你可以自己学习,甚至自己写稿。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值