如果你需要提供一个复杂的组合用户界面来输入元数据,这时就要添加设计器的支持。换句话说,除此之外没有别的办法来输入你自定义的元数据类型。添加设计器的支持,首先你要创建一个
Editor
作为自定义的类型,一个
Editor
其实就一个继承于
.NET
中的
System.Drawing.Design.UITypeEditor
类的子类。
安装
CodeSmith
后在,在
C:/Program File/CodeSmith/
SampleProjects
文件夹下有很多
SampleCustomProperties
的工程。例如:
DropDownEditorProperty
是一个把字符串和布尔类型的值结合在一起的元数据,它提供了一个类
DropDownEditorPropertyEditor
继承于
System.Drawing.Design.UITypeEditor
。
在使用的时候跟其它的元数据类型是一样,不过别忘记添加对程序集的引用,引用
CodeSmith
默认的是不认识该类型的。
当用户想要编辑
DropDownEditProperty
时,单击
CodeSmith
属性面板将会显示如下的自定义对话框:
[Editor(
typeof
(CodeSmith.Samples.DropDownEditorPropertyEditor),
typeof
(System.Drawing.Design.UITypeEditor))]
public class DropDownEditorProperty
public class DropDownEditorProperty
<%
@ Property Name
=
"
DropDownEditorProperty
"
Type
=
"
CodeSmith.Samples.DropDownEditorProperty
"
Category
=
"
Options
"
Description
=
"
This property uses a custom dropdown editor.
"
%>
<% @ Assembly Name = " SampleCustomProperties " %>
<% @ Assembly Name = " SampleCustomProperties " %>