Home > Essentials, General > How to specify the CodeRush user information and use it inside text expansions

How to specify the CodeRush user information and use it inside text expansions

August 15th, 2011

Note, this article has been moved to the official DevExpress Support Center site. Please refer to the moved article as it might have further updates or additional comments. Thank you.

If you use the CodeRush code templates heavily, and they specify the author of the source code, you may find the IDE | User Info options page interesting. On this page, you can specify your first, last and middle name, and then use them inside the text expansions, for example, to create a file header and specify its author.

The information on the User Info page in the IDE Tools Options Dialog is personal for every user. If you create code templates that use the information from that page, other users that share the same templates do not have to edit templates. Instead, they only need to specify their names on the page, which is much easier. Here is what it looks like:

CodeRush User Info options page

By default, there are only three key/values available:

  • First Name – if not specified, automatically filled-in with the currently logged in user name.
  • Middle Name – your middle name
  • Last Name – your last name

You can add an additional key/value pair by clicking the New Record button. For example, you can specify your position or date of birth. Two other buttons allow you to edit or remove existing key/value pairs. Note that you cannot remove the three default key/values, only the items you have added manually.

The values provided on this page can be used by using the corresponding string providers. Here is the list of the user info specific string providers that will return the information that you request:

String Provider Name

Description

GetUserFirstName Gets the user first name
GetUserInfo Gets the user information specified by the key name passed as a parameter.
GetUserInitials Gets the user initials based on the user first and last name.
GetUserLastName Gets the user last name.
GetUserMiddleName Gets the user middle name.

Now let’s create a simple template that will generate the file header based on the information from the User Info page. Before we start, specify your first and last name, and add the company field on the options page. Here is what the template may look like:

//-----------------------------------------------------------------------
// <copyright file=""«?FileName»"" company=""«?GetUserInfo(Company)»"">
//     Author: «?GetUserFirstName» «?GetUserLastName»
//     Copyright (c) «?GetUserInfo(Company)», Inc. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

Once this template is expanded, you will see, inserted, a header similar to this:

//-----------------------------------------------------------------------
// <copyright file=""C:\Projects\TestClass.cs"" company=""DevExpress"">
//     Author: Alex Skorkin
//     Copyright (c) DevExpress, Inc. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

Bear in mind that you can put this header into all source files of your solution automatically with a single keystroke. To learn more, please read the appropriate topic. I hope you find this interesting.

—–
Products: DXCore, CodeRush Pro
Versions: 12.1 and up
VS IDEs: any
Updated: Nov/01/2012
ID: D106

Similar Posts: