|
The code snippet template itself is stored in an XML file. This file includes several tags
that we will now cover. The first important part in the XML document is the <Substitutions>
part. This is where you define the different variables that will be replaced when used in the Code
Customization Wizard. You will later on see that variables in the code template itself are written
as ${parameter name}. Each variable is written in the following structure:
<Variable>
<Name>Record Control Class</Name>
<Description>
Select the record control where this customization will be inserted
</Description>
<Type>RecordControlClass</Type>
</Variable>
|
The variable Name is the name as it appears in the code snippet itself and will also be shown
in the list of variables to be replaced in the Code Customization Wizard. Description is the prompt
displayed in the Code Customization Wizard to explain the meaning of this variable. Last is the variable
Type, including:
- Control - which will result in a drop down of all controls in the page
- TableName - which will result in a drop down of all tables in the database
- FieldName - which will result in a drop down of all fields in the selected table
- TableControlClass - which will list all table control classes in the page
- RecordControlClass - which will list all record control classes in the page
- RecordControl - which will list all controls in a selected record control
You have no limit as to the number of variables you can use in your code customization snippet.
For our example, I will use two variables: ”My Record Control” and ”My Control”. Their definition
will look like the following:
<Substitutions>
<Variable>
<Name>My Record Control</Name>
<Description>
Select the record control where this customization will be inserted
</Description>
<Type>RecordControlClass</Type>
</Variable>
<Variable>
<Name>My Control</Name>
<Description>Select the field whose value needs to be set.</Description>
<Type>Control</Type>
</Variable>
</Substitutions>
|
You can see that "My Record Control" is a record control class and "My Control" is the control
whose text attribute value is being set.
Now that we've defined our variables, we can continue and actually implement the code snippet.
The code snippet itself will be included in <Customizations> part of the XML file.
The <Customizations> part specifies where the code should be inserted using the <Class> tags.
Some of the values for this tag are:
- DataAccessClass
- RecordControl
- Page
- TableControl
- SQLAccessClass
After the Class tag, we define the type of code inserted. I usually use "sub" since it's either
a new method or code that goes into an existing method. For our example, the code customizations
section will look like:
<Customizations>
<Code>
<Class>RecordControl</Class>
<Type>Sub</Type>
<Content>
<![CDATA[
''' <summary>
''' Set the text property of a control to "hello world !"
''' </summary>
Private Sub RecordControl_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
${My Control}.Text = "Hello World !"
End Sub
]]>
</Content>
</Code>
</Customizations>
|
Please note that we use the XML [CDATA] tag in order to include the code as is and not have the XML
encode it for us when reading it from Iron Speed Designer. Another thing to note is our ability to write
several pieces of code to match the different framework versions. You can find an example for that in the
AJAX code customization.
Actually, that's the end of our journey. We have written our first code customization snippet and are
ready to use it. To summarize, the complete XML file content will look like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<CodeCustomization>
<Version>1.0</Version>
<Type>Page</Type>
<Description>
<![CDATA[
This will set "Hello World" into the text of the chosen field
]]>
</Description>
<FinishDescription>
<![CDATA[
You have now completed writing your first code customization
]]>
</FinishDescription>
<Substitutions>
<Variable>
<Name>My Record Control</Name>
<Description>
Select the record control where this customization will be inserted
</Description>
<Type>RecordControlClass</Type>
</Variable>
<Variable>
<Name>My Control</Name>
<Description<Select the field whose value needs to be set.</Description>
<Type>Control</Type>
</Variable>
</Substitutions>
<Customizations>
<Code>
<Class>RecordControl</Class>
<Type>Sub</Type>
<Content>
<![CDATA[
''' <summary>
''' Set the text property of a control to "hello world !"
''' </summary>
Private Sub RecordControl_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
${My Control}.Text = "Hello World !"
End Sub
]]>
</Content>
</Code>
</Customizations>
</CodeCustomization>
|
Now you are ready to make Iron Speed Designer a repository for all of your favorite code patterns.
|