This documentation is archived and is not being maintained.

Writing Code for Different Types of Work Items by Using the Client Object Model for Team Foundation

When you write code for different team projects, you can perform the same function on different types of work items that serve similar purposes. These types might be different because they come from different process templates, or a team might have customized them for a specific team project. For example, you might want to perform the same function on user stories and requirements, both of which should represent what customers require and value. Instead of writing separate code for each type of work item, you can generalize your code to work for both. In addition, one team might have customized the work item definition for user stories so that team members can estimate work in hours instead of in story points. You can avoid duplicating your own effort by adjusting your code to handle both the default and the customized strategies.

In this topic, you can find a code sample that performs a task on a specific type of work item that has not been customized, and then you can learn how to refactor that code to support certain kinds of customizations. For more information about how to customize types of work items, see Customize team projects and processes.

In this topic

This code sample prints trees of all user stories in each team project on a server and includes estimates for each story that has no children. To use this sample, you create a console application, add references to the following assemblies, and then replace the contents of Program.cs ( or Module1.vb ) with the following code.

No code example is currently available or this language may not be supported.

This sample modifies the PrintTrees method to determine whether each work item uses the story points field or the baseline work field and to print the estimate from that field. To use this sample, you replace the line Console.WriteLine(target.Fields["Story Points"].Value); in the PrintTrees method with the following code.

No code example is currently available or this language may not be supported.

You can group into categories different types of work items that serve the same or similar purposes in different team projects. You can write code to perform the same function on all work items that belong to a category. This sample prints estimates for any type of work item in the requirements category, such as user stories, requirements, and product backlog items.

To use this sample, replace the Main function from the previous sample with the following code.

No code example is currently available or this language may not be supported.
Show: