惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
博客园 - Franky
罗磊的独立博客
博客园 - 司徒正美
S
SegmentFault 最新的问题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
小众软件
小众软件
美团技术团队

博客园 - jirong

SQL2005 读取 XML 数据 SHTML 教程 automation服务器不能创建对象 C#动态方法调用 - jirong - 博客园 加密存储过程,函数,触发器,视图的破解 - jirong - 博客园 SQLServer和Oracle的常用函数对比 窗口最大化 - jirong - 博客园 存储过程编写经验和优化措施 ASP.NET 2.0 Internet安全之参考实现 常用正则表达式 - jirong - 博客园 对象序列化 游标的用法 javascript事件查询 JavaScript就这么回事 ASP.NET2.0+SQL Server2005构建多层应用 Microsoft .NET Pet Shop 4 架构与技术分析 分页控件 ASP.NET 调味品:AJAX 我写的第一个CodeSmith模板(添加修改数据页面)
CodeSmith应用(四):实现选择路径对话框
jirong · 2006-04-13 · via 博客园 - jirong

首先我们要添加<%@ 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;
         } 
}

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


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


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