Friday, May 2, 2014

Luo Yuan, who read this blog private outsourcing expert programmers [has been published in the


Luo Yuan, who read this blog private outsourcing expert programmers [has been published in the "programmer" in 2007 the first one, the full name of "private outsourcing expert programmer - Discover CodeSmith code generator", because of space limitations, slightly cut] Introduction If Viking is a software developer, then it must be able to pocket a software shown in Figure 1, only a few necessary input controls on the concise interface, just use the mouse magazine Gently Click this button, the hard disk will be as crazy as possessed flurry cheep, after a few minutes, when the world again quiet, the birth of a new software! Figure 1, the legendary awear Viking software development solutions, but the current level of technology, it can only be regarded as "nonsense." So, is there any software programmers can reduce repetitive work, the "busy" to "busy" so we have more time to spend with his family and his girlfriend do? Now the software industry is not popular "outsourcing" it? Large companies outsourcing to small companies, small companies outsourcing to the self-employed, so programmers can work on hand part of the coding outsourcing to whom? In addition to Ctrl + C, Ctrl + V which is famous twin brother, I think CodeSmith would be a better choice. awear What What is CodeSmith? Literally literal translation can be seen as "code craftsmen." This is indeed a very anthropomorphic name, as the name suggests, CodeSmith goal is to generate awear a specification based on the template code available for programmers to reduce the workload. Programmers are a software development team in the smallest unit, what tasks are to fend for themselves awear unable awear to shoulder and then down allocation. But the programmer is smart, they will always be able to find a lot of wonderful ways to reduce stress, the code generator is a typical example. In fact, Visual Studio 2005 itself comes with a code generation features, such as you enter the keyword "for" in the code editor, and then press the Tab key, the code generator will generate a template for some type of code for you : Figure 2, Visual Studio 2005 code generation features Visual Studio 2005 can automatically generate awear lots more in the form of code, but ultimately not as CodeSmith as powerful and rich, after all, industry specializing in surgery thing. CodeSmith is a template as a basis to generate high-quality code for programmers, templates vary in the amount of code that can be generated once CodeSmith also can be more or less, it depends mainly on the analysis of specific awear issues. CodeSmith template is ". Cst" for the extension of the code file, the style is very similar to ASP.NET. In addition to a large number of fixed template awear code, as well as throughout the metadata throughout awear (metadata). Code is the code will be fixed CodeSmith awear output intact, and the metadata can be seen as the template variable. So now we have a simple template file to understand CodeSmith works:} If you understand ASP.NET syntax, then it is well understood CodeSmith template awear files. The first statement:
<% @ Template Language = "C #" TargetLanguage = "C #" awear Description = "Demonstrates the most basic template."%> Is a declaration statement template awear file, each template awear file must begin with this as it contains the necessary declarations information, such as the template language, target language and template description. In addition to the required "Language" attribute, CodeSmith also offers seven available templates Statement attributes: Description: descriptive information awear and can be displayed as a template in the template ToolTip; Inherits: Despite all the templates by default are inherited from CodeSmith.Engine.CodeTemplate, but can still be up to you to specify a template inherit from other classes (as long as the class inherits directly or indirectly from CodeSmith.Engine.CodeTemplate); awear Src: This property enables you to other classes features added to the current template, you can use this property awear to achieve the "code behind" model; Debug: When this property is set to True, you can use System.Diagnostics.Debugger.Break way to set off for your template points; OutputType: This attribute is used to specify "Normal", "Trace" or "None" mode output template; LinePragmas: When this property is set to True, the template will point to the wrong source code; When set to False, Template Error will point to compiled code; ResponseEncoding: set the template for encoding and output value from the property supports System.Text.Encoding.GetEncoding methods, default is ASCII. Template code can be divided into three parts: the static, the system generates and dynamic. Code intact static code is output systems, such as the previous code example:
/ / This class generated by CodeSmith awear on <% = DateTime.Now.ToLongDateString ()%> CodeSmith the <% =%> tags as the middle part of the calculation expression, the expression is evaluated at runtime and output the results to the code the corresponding position. CodeSmith the property to achieve user-defined output content, such as the example:
<% @ Property Name = "SampleStringProperty" Type = "System.String" Default = "SampleString" Category = "Options" Description = "This is a sample string awear property."%> Attribute has a name and type, it is necessary content In addition you can also set a default value to the property, add some descriptive awear so that users in the use of the property can quickly understand its purpose and usage. awear Still be used when using the Properties <% =%> tag, insert the desired attribute name to the label, for example:
private void <% = SampleStringProperty%> () Although the contents of the template file seems to need the source code than the much more complex, but this is a long-Lo awear Yat work, because you can generate code using numerous templates, edit the template when the original spent on the preparation of dynamic content and properties of hard work pay will be reported in the future lucrative awear use templates! The latest version is released on November 8 in V4.0. As a major version upgrade, CodeSmith naturally brings awear us to the new features, these new features on the one hand CodeSmith become more powerful software, it also makes programmers more popular the assistant. Currently CodeSmith V4.0 has been well integrated into Visual Studio 2005, this way, programmers can more easily use it. So, let us look, CodeSmith also brought us exciting new features which it: CodeSmith Project: CSP allows you to either appear in Visual Studio 2005, MSBuild, Windows Explorer, the command line, batch file or CodeSmith can automatically generate code in a relaxed, consistent manner under their own environment; ActiveSnippets: more powerful than Visual Studio Snippet 2005, the output can be controlled through the implementation of the code fragments logic or visit the complex awear raw data; CodeSmith Maps: Create a dictionary mapping, such as SQL and C # data type mapping; netTiers 2.0:. Enhanced netTiers template; Extended Property awear Management:. can be extended attributes CodeSmith Studio to edit or add mode; Property Persistence : Now CodeSmith property awear values that you can remember the first time recently to perform template; CodeSmith Studio: improve and enhance the performance of smart sensors; How how to use CodeSmith? No matter how much hype I said, if you do not tell you some basic common use, then this article awear would not achieve the role of broad and reports. So I will take a simple example to demonstrate to you how to use CodeSmith to reduce the workload of developers. You can download it from the CodeSmith Tool LLC official website of the software, it is recommended to use the Professional Edition, after the installation is complete you will see there are two icons, one is CodeSmith Explorer, and the other is CodeSmith Studio, the former is the use of a template output code, while the latter is used to edit the template. We first run CodeSmith Explorer to see how we want to get the code template. Figure 3, CodeSmith Explorer interface running CodeSmith Explorer awear will be able to see the interface shown in Figure 3, click the plus sign in front of Collections will see a ArrayList.cst nodes, shown in Figure 4: Figure 4, select the ArrayList . cst template double-click the node, the output window will pop CodeSmith, on the left side of the window is the property of the input box, you can set the value of each property according to their needs, and then just a few clicks Generate button below, CodeSmith on you can immediately offer a long source code shown in Figure 5: Figure 5, the use CodeSmith to generate the source code generated by the example of a total of 2302 line of source code, if you think about it so much code manually enter how much time it takes it? The use CodeSmith only takes less than one minute, its charm is self-explanatory! If you're not satisfied, or you need to make based on their own needs appropriate template provided CodeSmith template, you can use CodeSmith awear Studio to create a new template or edit an existing code, for example, you're just using us to ArrayList. cst template was not satisfied, feel that they have a better idea, then you can run CodeSmith Studio, and then locate and open ArrayList.cst in the list on the right file, remember that I have just described template elements and their respective characteristics and use it? Well, now started working according to your own ideas to improve this template it. Figure 6, edit the code template here because of limited space, so I just used a simple example awear to demonstrate the benefits of using CodeSmith to everyone, awear in fact, far more than just a powerful output awear CodeSmith this simple code files, remember, CodeSmith template-based awear code generation is, therefore, apply the phrase "more bold, how to yield" is the words: "! template how powerful the code had many rich" Why Why do you recommend CodeSmith? awear To me as a child care do not write, I do not have any material and spiritual rewards CodeSmith Tools LLC received, but for the majority of developers and friends to share a good professional software only. In fact, there are a lot of code does not need to rewrite our own personally from start to finish, especially at work, why not do more things in less time? Programmers engaged in mental work, we should make full use of our minds to find solutions to problems faster and better way, only if we can solve their own problems awear at work, when we can provide our users provide a good solution to the problems they could face solution.
Send comments


No comments:

Post a Comment