zoukankan      html  css  js  c++  java
  • CodeSmith实用技巧(八):生成的代码输出到文件中

    CodeSmith中,要把生成的代码文件输出到文件中,你需要在自己的模版中继承OutputFileCodeTemplate类。

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

    OutputFileCodeTemplate主要做两件事情:

    1.它添加一个名为OutputFile的属性到你的模版中,该属性要求你必须选择一个文件;

    2.模版重载了方法OnPostRender(),在CodeSmith生成代码完成后把相应的内容写入到指定的文件中去。

    如果想要自定义OutputFile属性弹出的保存文件对话框,你需要在你的模版中重载OutputFile属性。例如:你希望用户选择一个.cs文件来保存生成的代码,需要在你的模版中添加如下代码:

    <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 string OutputFile
    {
        
    get {return base.OutputFile;}
        
    set {base.OutputFile = value;}
    }

    </script>
    支持TerryLee的创业产品Worktile
    Worktile,新一代简单好用、体验极致的团队协同、项目管理工具,让你和你的团队随时随地一起工作。完全免费,现在就去了解一下吧。
    https://worktile.com
  • 相关阅读:
    POJ2253 Frogger
    搜索专题(复习)
    机器学习资料整理
    51nod 1873 初中的算术
    Canny检测理解和Matlab实现
    Floyd+限制路径步数(快速幂优化)
    bitset优化背包问题
    Educational Codeforces Round 44 (Rated for Div. 2)
    BZOJ 3224 SBT 普通平衡树
    本科课程大数据基础
  • 原文地址:https://www.cnblogs.com/Terrylee/p/306233.html
Copyright © 2011-2022 走看看