How to specify the CodeRush user information and use it inside text expansions
If you heavily use the CodeRush code templates which 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, but instead, only need to specify their names on the page, which is much easier. Here is what it looks like:
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 are 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 get 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 automatically into all source files of your solution via a single keystroke. To learn more, please read the appropriate topic. I hope you find this interesting.
—– Products: DXCore, CodeRush Pro Versions: 11.1 and up VS IDEs: any Updated: Aug/16/2011 ID: D106