Adding Designer Support

Deprecated

This feature is deprecated and will be removed in a future version.

If your custom metadata requires a complex user interface (anything beyond the simple text edit control provided by the property grid) to edit, you'll need to add designer support. Otherwise, there won't be any way for the user to enter values for properties that make use of your metadata type. To add designer support, you'll need to build an editor for your type or use an existing UITypeEditor. An editor is simply a class that subclasses the .NET System.Drawing.Design.UITypeEditor class.

You can find the source code for several CodeSmith Generator custom designers in your extracted template folder. The default template folder is located in the My Documents folder (Documents\CodeSmith Generator\Samples\<Version>\Projects\CSharp\CustomPropertiesSample\

For example, DropDownEditorProperty is a class that wraps up a string and a boolean value together into a single piece of metadata. To edit this data, it provides a class, DropDownEditorPropertyEditor, which derives from UITypeEditor. The declaration of DropDownEditorProperty is decorated to indicate that this is the editor class that CodeSmith Generator should use in the property grid:

[Editor(typeof(CodeSmith.Samples.DropDownEditorPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public class DropDownEditorProperty

In a template, you can use this metadata type just like any other (although you need to remember to reference its assembly, because CodeSmith Generator doesn't know about this type by default):

<%@ Property Name="DropDownEditorProperty" Type="CodeSmith.Samples.DropDownEditorProperty" Category="Options" Description="This property uses a custom dropdown editor." %>
<%@ Assembly Name="SampleCustomProperties" %>

When the user wants to edit the DropDownEditProperty and clicks in the property sheet, CodeSmith Generator will display the custom designer:


For more information on building custom designers please read Building custom UITypeEditors.

Using an predefined UITypeEditor

Here is a compiled list of all UITypeEditors that CodeSmith Generator ships with.

NameAssemblyObsoleteDescription
CodeSmith.Engine.CodeFileParserPickerCodeSmith.Engine
Allows you to browse for a CSharp or VisualBasic class file.
CodeSmith.Engine.XmlPropertyFilePickerCodeSmith.Engine
This type editor can be used on a class that supports XML serialization to allow the user to pick an XML file and have that XML file deserialized into the target class.
CodeSmith.Engine.XmlSchemaFilePickerCodeSmith.Engine
Allows you to browse for an XSD Schema.
CodeSmith.CustomProperties.AssemblyFilePickerCodeSmith.CustomProperties
Allows you to browse for an assembly.
CodeSmith.CustomProperties.FileNameEditorCodeSmith.CustomProperties
Allows you to browse for a file.
CodeSmith.CustomProperties.NameValueCollectionEditorCodeSmith.CustomPropertiesYESAllows you to quickly edit an NameValueCollection.
CodeSmith.CustomProperties.StringCollectionEditorCodeSmith.CustomPropertiesYESAllows you quickly edit a string collection.
CodeSmith.CustomProperties.XmlSerializedFilePickerCodeSmith.CustomProperties
Allows you to browse for an Xml file.

Please note that you will need to add the following Assembly Directive for any UITypeEditor listed above that is defined in the CodeSmith.CustomProperties assembly.

<%@ Assembly Name="CodeSmith.CustomProperties" %>
It is worth noting that the .NET Framework also ships with many built-in UITypeEditors.