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
  • 相关阅读:
    mangodb学习0.1 概念
    express 学习笔记(一)路由
    vue配置路由
    screenX, clientX, pageX
    svg的世界、视窗、视野
    window.print()打印网页(一)
    cookie基础
    BOM基础
    Java三大特征:封装 继承 多态
    面向对象
  • 原文地址:https://www.cnblogs.com/Terrylee/p/306233.html
Copyright © 2011-2022 走看看