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

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园_首页
雷峰网
雷峰网
V
Visual Studio Blog
爱范儿
爱范儿
A
About on SuperTechFans
量子位
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
S
SegmentFault 最新的问题
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 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;
         } 
}

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


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


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