Register
Tuesday, January 06, 2009
Forum
 
Adding Custom Templates
Last Post 17 Jun 2008 08:45 AM by eurowise. 0 Replies.
Printer Friendly
Sort:
PrevPrev
You are not authorized to post a reply.
Author Messages
eurowise
Basic Member
Basic Member
Posts:107


--
17 Jun 2008 08:45 AM  
Version 3.0 supports the concept of custom templates. You can now add your own templates and execute them. This feature is not yet well documented in the help. Here is a quick tutorial how you can add your own templates. (You can download a Word document version of this from the download area).

The Projects folder contains a sub-folder named Common, which in turn contain a single file named Template. This file is used as a template to generate custom data sources. You can double-click on it to view its content. You can customise it.

<?xml version="1.0"?>
<DataSource>

</DataSource>

The CSharp and VB.NET sub-folder under the Templates folder in Code Explorer also each contains a sub-folders named Common. These files are used as templates to generates the VB.NET and CSharp custom templates. You can double click on them to view their content. You can customise them.

CSharp

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="DataSource"/>
</xsl:template>
<xsl:template match="DataSource">
public class $TemplateName$
{

}
</xsl:template>
</xsl:stylesheet>


VB.NET

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="DataSource"/>
</xsl:template>
<xsl:template match="DataSource">
Public Class $TemplateName$

End Class
</xsl:template>
</xsl:stylesheet>

To add a custom template, use the following procedure:
1.Right click on the Common sub-folder under the Projects folder
2.Select Add Template from the context menu
3.Name the template (e.g. Audit). Choose a name that will be used to generate your classes.
4.Three documents are added and edited in the VS IDE:
a.Projects\Common\ Audit.xml (XML data source)
b.Templates\VB.NET\Common\ Audit.xsl ( VB.NET XSLT template that can be used to generate the VB.NET class)
c.Templates\CSharp \Common\ Audit.xsl ( VB.NET XSLT template that can be used to generate the VB.NET class)
5.Modify the Audit.xsl templates:

CSharp

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="DataSource"/>
</xsl:template>
<xsl:template match="DataSource">
public class Audit
{
private void test()
{
}
}
</xsl:template>
</xsl:stylesheet>

VB.NET

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="DataSource"/>
</xsl:template>
<xsl:template match="DataSource">
Public Class Audit
Private Sub Test()

End Sub
End Class
</xsl:template>
</xsl:stylesheet>

6.Save and close your files
7.Open any solution that contains at least one project
8.Select a project where you want to generate the class
9.Right-click the Audit template under the Projects\Common folder
10.Select Execute Template from the context menu.
11.A class named Audit is added to the selected project in your solution.


Philip
You are not authorized to post a reply.

Active Forums 4.0