CodeSmith应用(四):实现选择路径对话框

发表时间:2006-03-19 16:59:00 浏览次数:1496
关键字: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 == 0return this.CodeTemplateInfo.DirectoryName + "output\\";

                   
return _outputDirectory;
         }
         
set
         {
                   
if (!value.EndsWith("\\")) value += "\\";
                   _outputDirectory 
= value;
         } 
}

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


    单击选择路径按钮后我们就可以看到这样的窗口


    选择后相应的路径值就会填入属性框。

来源:http://bear-study-hard.cnblogs.com/archive/2006/01/12/315838.html

FeedBack


还没有任何评论...
Title:
 
Name:
 
URL:

Comments:
 

Because of the cache,you may see your comments several minutes later.


关于我们 关于希丁 广告合作 业务范围 网站地图 工作机会
copyright @ 2003 - 2005 xding.com  蜀icp备05022311号
tel:(028)66380789 email:xdings#gmail.com(请将#修改为@)
my photo v1 v2 v3 Valid XHTML 1.0 Transitional