CodeSmith practical skills (8): output the generated code to a file

Source: Internet
Author: User
In CodeSmith, to output the generated code file to a file, you need to inherit the OutputFileCodeTemplate class from your own template. % @ CodeTemplateLanguageC # targetreceivagec # InheritsOutputFileCodeTemplateDescriptionBuildcustomaccesscode. %

In CodeSmith, to output the generated code file to a file, you need to inherit the OutputFileCodeTemplate class from your own template. % @ CodeTemplateLanguage = "C #" TargetLanguage = "C #" Inherits = "OutputFileCodeTemplate" Description = "Buildcustomaccesscode." %

InCodeSmithTo output the generated code file to the file, you need to inherit from your own templateOutputFileCodeTemplateClass.

<%@ CodeTemplate Language="C #"TargetLanguage="C #"Inherits="OutputFileCodeTemplate"Description="Build M access code." %>
<%@ Assembly Name="CodeSmith. BaseTemplates" %>

OutputFileCodeTemplateWe mainly do two things:

1. It addsOutputFileTo your template, this attribute requires you to select a file;

2The template reloads the method.OnPostRender (), InCodeSmithAfter the code is generated, write the corresponding content to the specified file.

If you want to customizeOutputFileThe "save file" dialog box pops up in properties. You need to reload it in your templateOutputFileAttribute. For example, you want to select. CsTo save the generated code, add the following code to your template:

<Script runat="Template">
//Override the OutputFile property and assign our specific settings to it.
[FileDialog (FileDialogType. Save, Title="Select Output File", Filter="C # Files (*. cs) | *. cs", DefaultExtension=". Cs")]
Public Override StringOutputFile
{
Get {Return Base. OutputFile ;}
Set {Base. OutputFile=Value ;}
}
Script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.