zoukankan      html  css  js  c++  java
  • CodeSmith应用(四):实现选择路径对话框

    首先我们要添加<%@ Assembly Name="System.Design" %>命名空间。然后我们在模板中自定义一个属性,用来表示要存储的路径。其中我们使用了this.CodeTemplateInfo.DirectoryName得到当前模版所在路径作为默认路径。

    private string _outputDirectory = String.Empty;
    [Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))] 
    [Optional]
    [Category("Output")]
    [Description("The directory to output the results to.")]
    public string OutputDirectory 
    {
    get
             {
    // default to the directory that the template is located in
    if (_outputDirectory.Length == 0) return this.CodeTemplateInfo.DirectoryName + "output\\";
    return _outputDirectory;
             }
    set
             {
    if (!value.EndsWith("\\")) value += "\\";
                       _outputDirectory = value;
             } 
    }

    这样编译运行后我们就可以看到如下效果:

  • 相关阅读:
    java文件配置MySQL
    logback.xml
    Apache Commons之commons-lang
    Codec入门
    Mysql命令增加、修改、删除表字段
    markDown的简单使用
    Vert.x核心包各功能模块详解
    StringJoiner使用详解
    Vert.x初体验
    Docker镜像备份与迁移
  • 原文地址:https://www.cnblogs.com/hsapphire/p/1692179.html
Copyright © 2011-2022 走看看