To do well, you must first sharpen your tools. Make sure that the server is not cut by mistake. These idioms and sayings tell us that we should take good care of the tools used before doing things, so that we can use them with ease and get twice the result with half the effort! In ancient times, it was even more so today in information technology.
AsProgramEmployee, daily work isCode, Reasonable configuration of the IDE we use will make our work get twice the result with half the effort. Some may say that the current IDE is very intelligent and does not need to be manually configured. Indeed, today's tools are getting better and better. Almost all common development tools have smart prompts, auto-completion code, and other caring functions, which brings great convenience to our work, but there are still some repetitive tasks that need to be done manually. For example, when creating a class, we often need to add information about ourselves or the company, copyright, and creation time. These things are generally fixed, therefore, we can create a template. This information is automatically generated every time a class is created. Not only classes, interfaces, CSS files, and so on. This method can be used not only when writing code, but also in normal work. For example, we often send emails, and the mail format at work is usually relatively fixed, therefore, we can create a template and so on. Any other office products such as word can be easily configured.
In fact, the most important thing is this kind of will-not-do idea. If one thing has been repeated for more than two times, we should think about whether there is any way for us to stop repeating it. Generally, this is true. Let's get started with the topic. Use specific examples to explain the benefits of this idea.
1. Open the installation directoryClass.zipDirectory:
32-bit c: \ ProgramFiles \ Microsoft Visual Studio 10.0 \ common7 \ ide \ itemtemplates \ CSHARP \ code \ 2052
64-bit c: \ ProgramFiles (x86) \ Microsoft Visual Studio 10.0 \ common7 \ ide \ itemtemplates \ CSHARP \ code \ 2052
Modify the class. CS file in class.zip to the desired content. The following is my modified class:
/* **************************************** * ************************** Created: liu Shuijing * Time: $ time $ * Note: * blog: Http://blog.csdn.net/liushuijinger **************************************** ************************** */ Using System; Using System. Collections. Generic; $ If $ ($ Targetframeworkversion $ >= 3.5 ) Using System. LINQ; $ endif $ Using System. text; Namespace $ Rootnamespace $ { Public Class $ Safeitemrootname $ {}}
Here, "$ xxx $" is used as the template variable. For example, the above $ time $ will display the current system time when creating a class. The specific variable description will be further described below.
The next step is to register the modified class so that vs can recognize it:
2. Visual Studio 2010 Command Prompt(Click Start, point to all programs, microsoftvisual studio 2010, and Visual Studio Tools, and then click Visual Studio command prompt (2010)")Run devenv/installvstemplates ". Wait for a moment to open vs2010, create a project, add a class, and then you will know the result.
It seems that the four in the red box can be used. I use the fourth one. If you are interested, try other ones.
The parameters recognized in the template and their descriptions are as follows:
parameter |
description |
clrversion |
Public Language Runtime (CLR) current version. |
guid [1-10] |
used to replace the project in the project file guid guid . guid1) ). |
itemname |
name provided by the user in the Add new project dialog box. |
machinename |
current computer name (for example, computer01 ). |
projectname |
the name provided by the user in the new project dialog box. |
registeredorganization |
HKLM \ Software \ Microsoft \ Windows NT \ CurrentVersion \ registeredorganization registry key value. |
rootnamespace |
root namespace of the current project. This parameter is used to replace the namespace only in the items to be added to the project. |
safeitemname |
the name provided by the user in the " Add new item " dialog box, all unsafe characters and spaces are removed from the name. |
safeprojectname |
the name provided by the user in the " new project " dialog box, all unsafe characters and spaces are removed from the name. |
time |
with dd/mm/yyyy 00:00:00 the current time in the format. |
userdomain |
current user domain. |
username |
current user name. |
webnamespace |
name of the current website. In Web this parameter is used in the form template to ensure that the class name is unique. If the website is located in Web under the root directory of the server, the template parameter is parsed to Web root directory of the server. |
Year |
ToYyyyThe current year. |
Note: The template parameters are case sensitive!
Solemnly declare: this blog is not intended to teach you how to customize class templates, but to explain the truth through this article, that is, the spirit of the future. It makes no sense to simply write a custom class template, because it can be found on the Internet. What we lack is often this kind of thinking. With the guidance of our thoughts, the direction of action will be clearer and make us more efficient.
We can only improve and surpass ourselves. If we are comfortable with the status quo, we will only stagnate or even go backwards. As the saying goes: if you do not enter, you will leave. Therefore, if you want to keep improving, it is essential to constantly surpass yourself. After reading this blog, everyone will join me. make progress together and improve together!