It seems that more and more people are interested in DCG. I am very happy, but everyone doesn't have to be too anxious, I am also a preview of everyone while doing, this is always better than waiting for all. Many, you can know the first hand message. ;-)
However, I don't want to drag too long, so I will upload a friend after get off work on Friday, and I will upload an example of reading an XML file mentioned last time. The download address is
Http://www.swallow.net.cn/dcg/dcg.ziphtp://www.swallow.net.cn/dcg/constructclassforxml.zip
Thanks to friends, thank you, thank you for me to provide space ^ _ ^ In order to make readers can use DCG immediately after downloading, I think it is necessary to describe the syntax of the dynamic template here, which is very simple, the rules are as follows:
<% @Header params = "value"%>, this form of TAG is the template of Headers, all Headers supported by the template as follows: <% @ Template language = "Language" [name = "templatename"] [version = "] [Version =" TemplateVersion "]%>, template must have such a header, with this header, a template is the correct template, and its language property specifies the language of the dynamic code in the template. This header can only appear once. <% @ AskLOCATION = "AssemblyLocation"%>, this header pointed out which assembly to reference, note that the referenced assembly must be in the root of the template, and can not have any path information when specifying the reference, such as: < % Assembly location = "myassembly.dll"%>. This TAG can appear multiple times. <% @ Import namespace = "namespace" [as = "alias"]%>, just like Using Namespace in C #, this header imports the dynamic code in the template to use the namespace. It can appear multiple times. <% @ Parameter name = "paramname" DataType = "paramdatattype"%>, this is a comparison key header, which specifies what parameters needed to operate, and what types are respectively. It can appear multiple times.
<% Code block%>, the code in this TAG is dynamic code, which does not return any value. <% = code block%>, the code in this TAG is dynamic code, which requires the return value. <% # function block%>, this TAG defines a template method that can be called any other place in the template. <% - Comment Block -%>, all words located within this TAG are considered comments, which will be ignored when parsing. DCG built-in class, this built-in class can be called anywhere, and it is currently included in the following: FileInfo, a system.io.fileinfo type property, with information about template physical files, such as CreationTime. CallTemplate method, this method has two parameters, and the Sword (String TemplatePath), the String TemplatePath, the first parameter requires the called template path, the second parameter requires the parameters required to be called template Object. In addition, the use of this nested template should pay attention to avoid cyclic calling, otherwise the dead cycle will appear. Ok, this is the basic template syntax, which is relatively simple, especially those who have used Codesmith or ASP. As for the OCD's grammatism, it is actually the same as the syntax of the template, just slightly different, the difference is as follows:
Template in Header is changed to OCD to clarify the difference between them. In the header, Parameter is changed to Object to express a parameter in the template, and in OCD is the difference in manufacturing an object. The dynamic code in the template is placed in <%%>, while the OCD is not used, because the code in the OCD is dynamic, but the method in the OCD is the same syntax in the template, i.e., <% #%>.
Ok, in addition to these different, they are exactly the same. After understanding the syntax of the template and OCD, you can download DCG V1.3.4.0 and start using it immediately. The DCG file package includes the following files:
Dcg.dll, DCG itself. Clean.exe, you need to use DCG to clean up the temporary file, if you don't talk to DCG in the same directory, then the temporary file generated is a problem, so you must pay attention. Dcgconsole.exe, previously mentioned console application, please refer to DCGCONSOLLE itself (enter DCGConsole if you enter a DCGCONSOLE) at prompt.
If you want to use Dcg.dll directly in your project, then the C # sample method of calling the template is as follows:
// Get the template manager. ItemplateManager TemplateManager = TemplateManager.instance; // Get the template through the Template Manager. Itemplate MyfirstTemplate = TemplateManager.getTemplate (ReadTemplateLocation), templatelocation; // Prepare the parameter objects you need to template. String TemplateNameParam = "123"; // Call the template to return the result. String result = myfirsttemplate.generatecode (new object [] {templateNameParam}); as you can see, call the template in your code is very simple, but I don't add any try catch code, actually use the template often because Various reasons, such as the template definition is not correct, the dynamic code in the template has a compilation error, and the dynamic code in the template has an error, so the DCG also gives a series of exception types to provide an exception classification and processing. About this reader to see every type of dcg.dll, I want to look at it enough to understand them, as for detailed documentation, I will give it slowly, after all, my time is not a lot.
Finally, I hope that the reader helps give comments, whether you think that DCG is still good or bad, I hope the reader will give feedback to DCG, so that I will strengthen it, thank you, and wish you a happy code!