zoukankan      html  css  js  c++  java
  • Using CustomProperties of CodeSmith

         1、FileNameEditor 

      FileNameEditor类可以让我们为用户提供一个标准的打开文件的对话框和保存文件的对话框,当然在使用FileNameEditor之前我们得先导入CodeSmith.CustomProperties程序集,如下:

    <%@ Assembly Name="CodeSmith.CustomProperties" %>
    <%@ Import Namespace="CodeSmith.CustomProperties" %>
     
    如何在我们得模板中使用FileNameEditor呢?如下:

    <script runat="template">
    private string _userFileName = @"D:\TEST\TEST.txt";
    [Editor(
    typeof(FileNameEditor), typeof(System.Drawing.Design.UITypeEditor)),
    Category(
    "Custom"), Description("User selected file.")]
    public string UserFileName
    {
          
    get {return _userFileName;}
          
    set {_userFileName= value;}
    }

    </script>


    这样,当我们执行我们得模板得时候,就可以看到UserFileName得属性旁边有一个打开文件对话框的按钮了。

    我们还可以通过设置FileDialogAttribute来定义文件对话框出项的起始目录:

    private string _openFileName = @"D:\TEST\TEST.txt";
    [Editor(
    typeof(FileNameEditor), typeof(System.Drawing.Design.UITypeEditor)),
    FileDialogAttribute(FileDialogType.Open, Title
    ="Select Input File"),
    Category(
    "Custom"), Description("User selected file.")]
    public string OpenFileName
    {
          
    get {return _openFileName;}
          
    set {_openFileName= value;}
    }



    这样,当你打开文件对话框时,系统会直接定位到 D:\TEST\TEST.txt。

         2、StringCollection
      这个属性让我们能为用户提供输入一字符串列表的功能,使用这个属性同样要先导入CodeSmith.CustomProperties程序集,然后添加这样的属性设置即可。
    <%@ Property Name="List" Type="CodeSmith.CustomProperties.StringCollection" Category="Custom" Description="This is the list." %>

    然后我们执行模板的时候就会有List 这样的属性,我们点击旁边的按钮,在弹出的String Collection Editor中就可以输入我们需要的字符串列表,按回车表示一个字符串结束。

    在代码中按照下面的方法使用输入的List:

    <% for (int i = 0; i < List.Count; i++%>
    <%= List[i] %>
    <% }
     %>


  • 相关阅读:
    Activex控件的IObjectSafety接口问题
    用delphi制作无界面的activex控件
    Delphi发布ActiveX控件 制作CAB包 数字签名相关
    Delphi创建ActiveX控件,实现安全接口及无界面代码
    Delphi 开发ActiveX控件(非ActiveForm)
    利用Delphi编写IE扩展
    解决IE9下交通银行网上银行无法输入密码的问题
    Delphi中COM自动化对象中使用事件
    Delphi不注册COM直接使用ActiveX控件并绑定事件
    C#中使用 SendMessage 向非顶端窗体发送组合键
  • 原文地址:https://www.cnblogs.com/pw/p/435203.html
Copyright © 2011-2022 走看看