首页 > 编程语言 >10 Tips to Boost Your Productivity with C# and Visual Studio 2008

10 Tips to Boost Your Productivity with C# and Visual Studio 2008

时间:2023-11-10 15:32:42浏览次数:51  
标签:10 Productivity C# Visual Studio test data unit developer

http://blogs.msdn.com/johnwpowell/archive/2008/03/23/10-tips-to-boost-your-productivity-with-c-and-visual-studio-2008.aspx

http://www.microsoft.com/downloads/details.aspx?familyid=E5F902A8-5BB5-4CC6-907E-472809749973&displaylang=en

http://dotnet.chinaitlab.com/CSharp/742310.html

Learn Key Bindings

It's an obvious and trivial thing, but the timesaving will add up, especially for those actions you perform tens or hundreds of times a day such as building and debugging.  Here are some basic bindings every Visual Studio developer should know:

  • Build: CTRL + SHIFT + B
  • Word completion: CTRL + SPACE
  • Start with debugging: F5
  • Start without debugging: CTRL + F5

Even expert Visual Studio developers can benefit by learning new bindings. Download the Visual C# 2008 Keybinding Reference Poster and hang it in your work area.

Generate XML Comments with GhostDoc

Instead of typing XML comments by hand, let a tool do the work for you. Although macros and snippets are reasonably effective for this, I would recommend Ghost Doc over any other solution. This free add-in uses customizable templates to generate consistent, English-readable documentation based on the current context.  To use it, right-click (or use CTRL + SHIFT + D) to document the current element.  For example:

This generates the following documentation (note GhostDoc split the property name into words and created a sentence from it):

Auto-Implement Properties

Take advantage of a new feature of C#: auto-implemented properties. Rather than creating a private backing field for your properties, let the compiler do it for you. The following demonstrates the syntax:

Use the code snippet to make this even faster.  Type prop (the shortcut for an auto-implemented property) followed by TAB TAB.  Then fill in the data type and property name:

Refactor

The refactor feature in Visual Studio is indispensable for many tasks, especially renaming, but one productivity feature I particularly like is Encapsulate Field. If you are unable to use an auto-implemented property, declare a private field and let Visual Studio generate the Property for you.  To use this feature, right-click on the field and select Refactor > Encapsulate Field...

The property is created for you:

Add Commands to Visual Studio 2008

Install the PowerCommands for Visual Studio 2008 to add several productivity commands such as:

  • Close all documents
  • Copy and paste a class (automatically renames)
  • Remove and sort using statements project-wide
  • Copy and paste references (including a project reference)

Install the Team Foundation Server Power Tools to add several TFS productivity commands such as:

  • Find in source control
  • Open source folder in Windows Explorer
  • Work item templates (can be used to set values on multiple work items at once)

Add your own productivity commands.  For example, to add Reflector so it automatically opens on the current project.

  • Select Tools > External Tools
  • Click Add
  • Name it Reflector and browse to the executable
  • Enter $(TargetPath) for the Arguments
Speed up Compilation with Project Configuration

You may build tens of times during a programming session, so don't enable anything that isn't absolute necessary such as code analysis and XML documentation.  Develop in Debug configuration, and switch to Release configuration just before check-in to run code analysis and generate XML documentation. In a large solution I recently worked on, this shaved a minute off compilation time.

The following shows code analysis disabled in Debug configuration:

The following shows code analysis enabled in Release configuration:

Let Visual Studio Generate Unit Test Code

Although it can't fully automate unit testing yet (check out Pex), Visual Studio does a good job of generating positive unit test code to give you a jump start.  To use this feature, right-click on an element you would like to test and select Create Unit Tests... 

Visual Studio generates the following test method:

Use Interface-Driven-Design

You probably never thought of an interface as a productivity feature, but it can be if your development process is driven by contracts instead of implementation.  Let me illustrate with a simplified example.  One developer owns the business layer and another developer owns the data access layer, and they need to agree on how to communicate to implement a new feature.  In some business object designs, business components will instantiate data components (or call a static method).  This is a problem from a design standpoint because the two become tightly coupled.  It is also a problem from the productivity standpoint because the business layer developer becomes dependent on the data access layer developer's implementation.  Interface-driven design (IDD) solves this issue.

Rather than the business component developer waiting on the data component developer, they meet to design and implement the interface.  Both developers are then free to go their separate ways and implement the components in parallel.  IDD also enables the business developer to mock the data access component, thereby removing any scheduling dependencies.  The following illustrates the design:     

Make a Mockery of Dependencies

Different developers may own layers or features that your component is dependent on, but don't let that slow you down.  Suppose you are responsible for the business layer which depends on the data access layer which in turn depends on database tables and stored procedures. Rather than waiting for dependent layers to be completed, mock the data access layer so you can implement and unit test the business layer. By the way, you should be using mocks anyway; otherwise your unit tests are more than likely integration tests.  I recommend Rhino Mocks.

Here is a sample unit test with mocks:

Data Drive Unit Tests

If you have a unit test that multiple inputs to fully test, you could write a test method for every possible combination, but data-driven unit tests are more efficient.  When the unit test is run, it loads data from a table and calls the unit test for each row.  You can access the data in the current row using the TestContext.DataRow property.

Once the test completes, you can view the results:

Published Sunday, March 23, 2008 12:48 PM by johnwpowell



标签:10,Productivity,C#,Visual,Studio,test,data,unit,developer
From: https://blog.51cto.com/emanlee/8303227

相关文章

  • 如何使用select库采集携程
    今天给大家带来一个select库编写的简单爬虫程序,主要是对携程的采集,代码中有一些制定的字符串比较难以理解,我有针对性的做了中文解释,一起来学习一下吧。```rustfnmain(){//创建一个TcpListener,监听指定的端口letlistener=TcpListener::bind("0.0.0.0:8000").unwrap();//......
  • 春秋云镜 Exchange WP
    春秋云镜ExchangeWPfscan扫描(icmp)Target39.100.160.90isalive[*]Icmpalivehostslenis:139.100.160.90:80open39.100.160.90:8000open39.100.160.90:22open[*]aliveportslenis:3startvulscan[*]WebTitle:http://39.100.160.90code:200l......
  • R : PCoA(第二版)
    #1.导入所需的库。library(vegan)library(tidyverse)library(ggalt)library(car)library(ggforce)library(ggpubr)library(patchwork)#2.定义所需的函数。pairwise.adonis1<-function(x,factors,p.adjust.m){#将输入转换为矩阵x=as.matrix(x)co=......
  • c#学习笔记-------------------Quartz.NET任务调度框架
    Quartz.NET任务调度框架 Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等。Quartz.NET允许开发人员根据时间间隔(或天)来调度作业。它实现了作业和触发器的多对多关系,还能把多个作业与不同的触发器关联。整合了Quartz.......
  • CSS:箭头
    一、箭头产生的原理1、设置一个div,然后给他设置样式:边框100px,上右下左颜色分别为绿、蓝、橘、红。然后设置div的高度和长度均为100px<template><divclass="about"><divid="demo12"></div></div></template><script>exportdefault{name:......
  • 获取iphone手机里面app的包名packagename
    首先进入appstore,查找你所要的app其次进入分享此app->拷贝链接,可以发送到社交软件:如网易云app的链接如下:https://apps.apple.com/cn/app/%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90-1%E4%BA%BF%E6%AD%A3%E7%89%88%E6%9B%B2%E5%BA%93%E6%9C%89%E5%A3%B0%E5%86%85%E5%AE%B9/i......
  • podman 容器管理 docker替代,进阶版本?
    简介Docker的一个缺点是它有一个中央守护进程,它以root用户的身份运行,这对安全有影响。但这正是Podman的用武之地。padman完全兼容docker命令和镜像。Podman是一个无守护进程容器引擎,用于开发、管理和在你的Linux系统上以root或无root模式运行OCI容器。安装安......
  • 面试必刷TOP101:24、二叉树的中序遍历
    题目题解深度优先搜索-递归publicclassSolution{/***代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可***@paramrootTreeNode类*@returnint整型一维数组*/publicint[]inorderTraversal(TreeNo......
  • 什么是DNS,A记录,子域名,CNAME别名,MX记录,TXT记录,SRV 记录,TTL值
    DNSDNS,DomainNameSystem或者DomainNameService(域名系统或者域名服务)。域名系统为Internet上的主机分配域名地址和IP地址。由于网络中的计算机都必须有个IP地址,来识别,互相之间才能通信,但让我们记住一大串的IP地址来访问网站显然是不可能的,所以用户使用域名地址,而DNS系统的......
  • IIS HTTP 500 - 内部服务器错误完美解决 IIS 服务器无法加载应用程序 '/LM/W3SVC/1/RO
    现象:       浏览ASP页面提示  500内部错误事件查看器中:        [1]:               服务器无法加载应用程序'/LM/W3SVC/1/ROOT'。错误是'没有注册类别'。                有关此消息的详细信息,请访问Microsoft联机支......