日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeSmith实用技巧(二):使用FileNameEditor

發布時間:2025/4/5 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeSmith实用技巧(二):使用FileNameEditor 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

FileNameEditor類給我們提供了在CodeSmith屬性面板中彈出打開或保存文件對話框的方式,在使用時,首先在模版中得添加對程序集CodeSmith.CustomProperties的引用。然后就可以在模版中定義一個屬性來使用FileNameEditor<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

?1<script?runat="template">
?2
?3private?string?_userFileName?=?@"c:\temp\test.txt";
?4
?5?
?6
?7[Editor(typeof(FileNameEditor),?typeof(System.Drawing.Design.UITypeEditor)),
?8
?9Category("Custom"),?Description("User?selected?file.")]
10
11?
12
13public?string?UserFileName
14
15{
16
17??????get?{return?_userFileName;}
18
19??????set?{_userFileName=?value;}
20
21}

22
23</script>
24
25

當我們執行該模版時,在屬性面板中同樣顯示為一個按鈕:

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />

單擊該按鈕,彈出一個保存文件的對話框:

我們也可以通過FileDialogAttribute來自定義彈出的對話框,修改模版為:

?1private?string?_openFileName?=?@"c:\temp\test.txt";
?2
?3
?4[Editor(typeof(FileNameEditor),?typeof(System.Drawing.Design.UITypeEditor)),
?5
?6FileDialogAttribute(FileDialogType.Open,?Title="Select?Input?File"),
?7
?8Category("Custom"),?Description("User?selected?file.")]
?9
10?
11
12public?string?OpenFileName
13
14{
15
16??????get?{return?_openFileName;}
17
18??????set?{_openFileName=?value;}
19
20}

21
22

彈出的對話框如下所示:

當我們想用一個文件夾的名稱來代替文件時,可以使用FolderNameEditor類。

?1<%@?Assembly?Name="System.Design"?%>
?2<script?runat="template">
?3private?string?_outputDirectory?=?@"c:\temp";
?4[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor),?typeof(System.Drawing.Design.UITypeEditor)),
?5Category("Custom"),?Description("Output?directory.")]
?6public?string?OutputDirectory
?7{
?8???????get?{return?_outputDirectory;}
?9???????set?{_outputDirectory=?value;}
10}

11</script>
12
13

FileNameEditor重要方法和屬性介紹:

公共方法:

名稱

描述

EditValue

使用由 GetEditStyle 方法提供的編輯器樣式編輯指定的對象

GetEditStyle

獲取 EditValue 方法所使用的編輯樣式

?

轉載于:https://www.cnblogs.com/Terrylee/archive/2005/12/27/305594.html

總結

以上是生活随笔為你收集整理的CodeSmith实用技巧(二):使用FileNameEditor的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。