<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>GAX</title>
        <link>http://geekswithblogs.net/EltonStoneman/category/8814.aspx</link>
        <description>GAX</description>
        <language>en-GB</language>
        <copyright>Elton Stoneman</copyright>
        <managingEditor>comments@sixeyed.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Sixeyed.Guidance.CodeGeneration: Technical Walkthrough</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2009/03/09/sixeyed.guidance.codegeneration-technical-walkthrough.aspx</link>
            <description>&lt;p style="text-align: center;"&gt;&lt;span style="font-size: 10pt;"&gt;[Source: &lt;a href="http://geekswithblogs.net/EltonStoneman"&gt;http://geekswithblogs.net/EltonStoneman&lt;/a&gt;] &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://geekswithblogs.net/EltonStoneman/archive/2009/03/07/code-generation-guidance-package.aspx"&gt;Code Generation Guidance Package&lt;/a&gt; on &lt;a href="http://www.codeplex.com/GAXCodeGeneration"&gt;CodePlex&lt;/a&gt; was designed to be extensible and reusable. There are three main C# projects, which isolate logic for code generation, and the UI and GAX components.  &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Sixeyed.CodeGeneration&lt;/em&gt; 	&lt;/p&gt;
&lt;p&gt;This is the core project, defining how metadata is represented and retrieved, and defining configuration for code generation runs. Metadata is defined in terms of: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;A metadata source, which contains the logic for connecting to the source &lt;/li&gt;
    &lt;li&gt;A metadata provider, which uses the source to provide a list of available items, and to populate requested items &lt;/li&gt;
    &lt;li&gt;Metadata items, which are a representation of the metadata, typically using an appropriate .NET framework class &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Code generation and UI logic always works on the interfaces which define these components, and the relationships between them: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030909_1806_SixeyedGuid1.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;In the &lt;em&gt;Add Generated Items&lt;/em&gt; recipe, the available source types, sources and providers are populated from the collection of &lt;strong&gt;IMetadataSource&lt;/strong&gt; objects held in the static &lt;strong&gt;SourceContainer&lt;/strong&gt; class (additional sources can be added to the container at runtime using the &lt;em&gt;SourceAssemblyConfiguration&lt;/em&gt; recipe argument – described in &lt;a href="http://geekswithblogs.net/EltonStoneman/archive/2009/03/08/sixeyed.guidance.codegeneration-sample-package.aspx"&gt;Sixeyed.Guidance.CodeGeneration Sample Package&lt;/a&gt;). When a provider is selected, &lt;em&gt;GetItemNames&lt;/em&gt; is called to populate the list of available metadata items. When the selected items are iterated over in a code generation run, &lt;em&gt;GetItem&lt;/em&gt; is called and the populated &lt;strong&gt;IMetadataItem&lt;/strong&gt; is loaded as a property for the T4 template. The metadata item exposes the provider, and the provider exposes the source so the template can connect directly to the metadata if it needs to. &lt;/p&gt;
&lt;p&gt;Each metadata interface has an abstract base class which implements it and contains core logic. For a given source, there may be an additional base class which abstracts logic common to that type of source. In &lt;strong&gt;Sixeyed.CodeGeneration.Metadata.Database.Source&lt;/strong&gt;, &lt;strong&gt;DatabaseSource&lt;/strong&gt; contains logic for accessing ADO.NET data sources in terms of &lt;strong&gt;IDbConnection&lt;/strong&gt; and &lt;strong&gt;IDbCommand&lt;/strong&gt; objects; &lt;strong&gt;SqlServerSource&lt;/strong&gt; contains overriding logic to specify &lt;strong&gt;SqlConnection&lt;/strong&gt; and &lt;strong&gt;SqlCommand&lt;/strong&gt; usage – any additional database sources would do the same. Similarly for the SOAP metadata source, the logic for accessing WSDL is abstracted into a base class which may be used by other sources (e.g. a WCF specific source): &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030909_1806_SixeyedGuid2.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IMetadataProvider&lt;/strong&gt; contains logic for accessing the source and retrieving a list of available items, and for populating a named item. The majority of logic is in the generic base class, so provider classes are quite simple. Simpler still are metadata item classes, which inherit the generic &lt;strong&gt;ItemBase&lt;/strong&gt; class, specifying the underlying type of the item (&lt;strong&gt;XmlSchema&lt;/strong&gt; in this case), without requiring any additional code. &lt;/p&gt;
&lt;p&gt;Logic for populating template properties and executing T4 templates is located in the Guidance project rather than the code generation project, as it is dependent on the specific T4 engine being used.  &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Sixeyed.CodeGeneration.UI&lt;/em&gt; 	&lt;/p&gt;
&lt;p&gt;The UI project contains generic user controls which represent metadata selections, and expose various events to notify of selection changes. The Guidance package Wizard uses these components rather than defining its own UI – the controls from this assembly allow code generation to be configured and invoked from a different UI host. &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Sixeyed.Guidance.CodeGeneration &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This project defines the GAX package and links together the code generation and UI components. The Guidance package is quite straightforward – it contains a single class &lt;strong&gt;AddGeneratedItems&lt;/strong&gt; for the action of generating items from metadata and adding them to the selected project. The action expects &lt;em&gt;SourceConfiguration&lt;/em&gt;, &lt;em&gt;SelectedItems&lt;/em&gt; and &lt;em&gt;TemplateConfiguration&lt;/em&gt; arguments; it connects to the source, iterates over the selected items and executes the template for each item. &lt;/p&gt;
&lt;p&gt;To collect the argument values, there are custom wizard pages and value providers for each, allowing a recipe to provide ready-configured settings, or build a UI to gather them from the user: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Sixeyed.Guidance.CodeGeneration.CustomWizardPages&lt;/strong&gt;. The custom Wizard pages use the static &lt;strong&gt;Metadata &lt;/strong&gt;class to share state for the configured metadata source and provider. They override &lt;em&gt;IsDataValid&lt;/em&gt; to determine if the page has collected enough information for the Wizard to proceed and the base class provides &lt;em&gt;EnableNextStep&lt;/em&gt; which will advance the Wizard by enabling the Next or Finish button as appropriate. The base class will read the &lt;em&gt;SourceAssemblyConfiguration&lt;/em&gt; recipe argument if provided, and use it to add any extra metadata assemblies at runtime. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Sixeyed.Guidance.CodeGeneration.ValueProviders&lt;/strong&gt;. The value provider classes are straightforward, reading optional arguments from the recipe and populating the relevant metadata settings. Custom recipes can specify value providers to load settings instead of Wizard pages, so the Wizard UI can be restricted. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;TODOs &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There are a couple of minor changes I'd like to make to the current codebase: &lt;/p&gt;
&lt;ul style="margin-left: 38pt;"&gt;
    &lt;li&gt;&lt;strong&gt;Sixeyed.Guidance.CodeGeneration.CustomWizardPages.SelectTemplate &lt;/strong&gt;defines its own UI, which should be moved to a user control in the UI project; &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Sixeyed.CodeGeneration.Generation.MemberName&lt;/strong&gt; contains methods for providing valid field and property names, but the Pascal and camel-case conversion is very basic; &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Sixeyed.CodeGeneration.UI.SourceUri&lt;/strong&gt; has some ugly hard-coding to decide which UI dialog it should show for different types of URI. It should be configurable, but I'm not happy moving it to an attribute of &lt;strong&gt;IMetadataSource&lt;/strong&gt;, as that brings the UI into the core project.  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And some additional metadata sources which I'll add at a future point – a Clipboard source providing access to clipboard data through text or XML providers, and a BizTalk source which will use the ExplorerOM for providers supplying application, group and instance information as metadata. &lt;/p&gt; &lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/129942.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2009/03/09/sixeyed.guidance.codegeneration-technical-walkthrough.aspx</guid>
            <pubDate>Mon, 09 Mar 2009 18:05:28 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/129942.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2009/03/09/sixeyed.guidance.codegeneration-technical-walkthrough.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/129942.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Sixeyed.Guidance.CodeGeneration Sample Package</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2009/03/08/sixeyed.guidance.codegeneration-sample-package.aspx</link>
            <description>&lt;p style="text-align: center;"&gt;&lt;span style="font-size: 10pt;"&gt;[Source: &lt;a href="http://geekswithblogs.net/EltonStoneman"&gt;http://geekswithblogs.net/EltonStoneman&lt;/a&gt;] &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The basic &lt;a href="http://geekswithblogs.net/EltonStoneman/archive/2009/03/07/code-generation-guidance-package.aspx"&gt;Code Generation Guidance Package&lt;/a&gt; on &lt;a href="http://www.codeplex.com/GAXCodeGeneration"&gt;CodePlex&lt;/a&gt; comes with an additional sample Guidance package. This sample is intended to demonstrate how the functionality of the base package can be customised to create a project-specific Guidance package, where you can easily add tailored code generation recipes to your package. In the basic package are the Wizard steps necessary to configure ad-hoc code generation, but there are also ValueProviders which can read configuration from recipes without requiring the whole user interface. &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Installation &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You'll need to modify the hard-coded paths and URIs in the sample package, so it doesn't come with an installed release. If you open the &lt;strong&gt;Sixeyed.Guidance.CodeGenerationSample&lt;/strong&gt; solution you'll see that it references the base &lt;strong&gt;Sixeyed.Guidance.CodeGeneration&lt;/strong&gt; and &lt;strong&gt;Sixeyed.CodeGeneration&lt;/strong&gt; assemblies. The sample contains a set of T4 templates in the &lt;em&gt;\Templates\Text&lt;/em&gt; directory, the XML configuration for the package and the XML includes for individual recipes. There's no additional code in the sample project, all the required functionality is in the referenced base package. &lt;/p&gt;
&lt;p&gt;Together with the GAX project, there's a database project which you can use to create a SQL Server database suitable for the data-bound recipes to run against. To install, run the &lt;em&gt;CreateDatabase&lt;/em&gt; script and then execute the SSIS package to populate data from the included Excel workbook (this is only necessary if you want to run the recipes as-is, otherwise you can modify the XML to use your own database). &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Sample T4 Templates&lt;/em&gt; 	&lt;/p&gt;
&lt;p&gt;There are T4 templates for each of the metadata providers in the base package. The scripts named &lt;em&gt;_Simple.tt&lt;/em&gt; are straightforward and begin with the name of the expected provider; to run them, you can use &lt;em&gt;Add Generated Items&lt;/em&gt; from the base package, select the relevant metadata and point to the template. To demonstrate more useful code generation, there are two more substantial templates: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;em&gt;ConfigurationSection.cs.tt&lt;/em&gt; – use the File source and the Text provider on this template. If you select &lt;em&gt;Configuration.txt&lt;/em&gt; (from the database project) as the source, the recipe will generate a typed configuration class, which has a static property to access the current config settings. The template can be easily extended to add a Default value for optional settings, and the same text file can be used to drive a different T4 template to generate the actual configuration settings; &lt;/li&gt;
    &lt;li&gt;&lt;em&gt;StoredProcedure.cs.tt&lt;/em&gt; – use the SQL Server database source and the Stored Procedure provider. Select a procedure and the recipe will generate a DAL class to execute the stored procedure. This class won't compile, as it inherits from a base class which isn't provided, but it demonstrates one approach for DAL generation. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Sample Recipes&lt;/em&gt; 	&lt;/p&gt;
&lt;p&gt;The included recipes demonstrate configuring one or more settings for code generation so that the Wizard can be tailored or avoided altogether. &lt;em&gt;Generate Stored Procedure&lt;/em&gt; shows this best, configuring the metadata provider using the &lt;strong&gt;SourceConfigurationValueProvider&lt;/strong&gt;: &lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Argument&lt;/span&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SourceConfiguration&lt;/span&gt;"&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Sixeyed.CodeGeneration.Metadata.SourceConfiguration, Sixeyed.CodeGeneration&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ValueProvider&lt;/span&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SourceConfigurationValueProvider&lt;/span&gt;" &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;SourceTypeName&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Database&lt;/span&gt;" &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;SourceName&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SqlServer Database&lt;/span&gt;" &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;SourceUri&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Data Source=x\y;Integrated Security=True;Initial Catalog=Scratchpad;&lt;/span&gt;" &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;ProviderName&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Stored Procedure Provider&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;      &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ValueProvider&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;    &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Argument&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;These settings are the equivalent of the first Wizard page, selecting the metadata source. It specifies the source type and source name, the URI for the source (in this case, the Scratchpad database included with the sample), and the metadata provider name. Having the &lt;em&gt;SourceConfiguration&lt;/em&gt; argument pre-populated means the first Wizard page will be skipped. The recipe also specifies the T4 template to use with the &lt;strong&gt;TemplateConfigurationValueProvider&lt;/strong&gt;: &lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Argument&lt;/span&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;TemplateConfiguration&lt;/span&gt;"&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Sixeyed.CodeGeneration.Generation.TemplateConfiguration, Sixeyed.CodeGeneration&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ValueProvider&lt;/span&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;TemplateConfigurationValueProvider&lt;/span&gt;"&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-left: 108pt;"&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: red;"&gt;   TemplatePath&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;x:\y\z\Templates\Text\StoredProcedure.cs.tt&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;      &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ValueProvider&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;    &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Argument&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; 	&lt;/p&gt;
&lt;p&gt;Only the template path is specified here, but other settings (target namespace, class name etc.) can also be provided. Having the &lt;em&gt;TemplateConfiguration&lt;/em&gt; argument populated means the third Wizard page will not be shown. Running this recipe gives you a Wizard form which only contains the second page, for selecting metadata items, pre-populated with the list which has already been loaded from the configured database: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030809_1747_SixeyedGuid1.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;- note that the other pages are not available, so the user is constrained to using the configured source and T4 template. &lt;/p&gt;
&lt;p&gt;Other recipes demonstrate configuring all or part of the settings needed for code generation. &lt;em&gt;Generate Simple&lt;/em&gt; runs a template which requires no metadata, so it connects to the metadata source, runs the template and adds the project output with no user intervention. &lt;em&gt;Additional Source&lt;/em&gt; demonstrates how you can extend the base code generation guidance package with additional metadata  sources and providers of your own, without rebuilding the base package. Specify the &lt;em&gt;SourceAssemblyConfiguration&lt;/em&gt; argument: &lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Argument&lt;/span&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SourceAssemblyConfiguration&lt;/span&gt;"&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Sixeyed.CodeGeneration.Metadata.SourceAssemblyConfiguration, Sixeyed.CodeGeneration&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ValueProvider&lt;/span&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SourceAssemblyConfigurationValueProvider&lt;/span&gt;" &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt; 			&lt;/span&gt;&lt;span style="color: red;"&gt;AssemblyList&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Sixeyed.CodeGeneration.Tests&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;      &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ValueProvider&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;    &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Argument&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; 	&lt;/p&gt;
&lt;p&gt;- and the .NET assemblies named in &lt;em&gt;AssemblyList&lt;/em&gt; (semi-colon separated) will be interrogated at run-time to identify &lt;strong&gt;IMetadataSource&lt;/strong&gt; and &lt;strong&gt;IMetadataProvider&lt;/strong&gt; implementations (there'll be more detail on those interfaces in a coming post). Any available classes will be added to the list of sources and providers shown in &lt;em&gt;Add Generated Items&lt;/em&gt;, and can also be used in &lt;em&gt;SourceConfiguration&lt;/em&gt; argument values. &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Usage &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;By providing custom recipes, you can tailor your own Guidance packages which contain recipes for generating classes or other artifacts based on established patterns. This gives the project team an easy way of ensuring consistency for common coding problems in the domain – configuration sections and stored procedure wrappers are simple examples. Note that the URIs and paths are hard-coded. The code generation guidance package will attempt to find a T4 template if the path is not fully stated, but it won't always succeed (there's an issue with returning the running &lt;strong&gt;GuidancePackage&lt;/strong&gt; instance that I haven't tracked down). In a typical project though, templates would be in SCM and source URIs would be consistent among developers, so fully-qualified hard-coded text shouldn't be a problem. &lt;/p&gt;
&lt;p&gt;I'll be extending the sample package to include other templates that may be useful starting points for common code generation tasks – enums to represent reference data, unit tests for .NET and BizTalk artifacts, MSBuild scripts and anything else that occurs. If you have any templates of your own which would fit in a standard library, let me know and I'll add you as a CodePlex contributor. &lt;/p&gt; &lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/129921.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2009/03/08/sixeyed.guidance.codegeneration-sample-package.aspx</guid>
            <pubDate>Sun, 08 Mar 2009 17:46:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/129921.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2009/03/08/sixeyed.guidance.codegeneration-sample-package.aspx#feedback</comments>
            <slash:comments>13</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/129921.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Code Generation Guidance Package</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2009/03/07/code-generation-guidance-package.aspx</link>
            <description>&lt;p style="text-align: center;"&gt;&lt;span style="font-size: 10pt;"&gt;[Source: &lt;a href="http://geekswithblogs.net/EltonStoneman"&gt;http://geekswithblogs.net/EltonStoneman&lt;/a&gt;] &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I've been working on a Guidance package which lets you use Visual Studio as a front end to generate items from T4 templates. Using a recipe wizard you choose your metadata from a Web service, database or file system source, and the template is rendered against each of the metadata objects you select. It's on CodePlex here: &lt;a href="http://www.codeplex.com/GAXCodeGeneration"&gt;Code Generation Guidance Package&lt;/a&gt;, and comes in two flavours. The basic Guidance package has a single recipe "Add generated items" – when you run it, you specify a metadata provider, select the items to use for metadata and the T4 template to render against the items.  &lt;/p&gt;
&lt;p&gt;The second package is a sample which extends the functionality of the main Guidance package with custom recipes. This demonstrates how you can define recipes for pre-configured generation types, so the user does not need to complete all the wizard pages – one example specifies a database connection string and a T4 template for generating stored procedure wrappers; to add a new DAL class, the user runs the recipe and just selects which stored procedure(s) they want generated.  &lt;/p&gt;
&lt;p&gt;Neither package comes with any Visual Studio solution or project templates, and they do not need to be used to create the original solution. Any existing project can make use of the code generation features by enabling the package(s) through &lt;em&gt;Tools…Guidance Package Manager&lt;/em&gt;. &lt;/p&gt;
&lt;p&gt;In this post I'll give an overview of using the basic &lt;strong&gt;Sixeyed.Guidance.CodeGeneration &lt;/strong&gt;package, and in future posts I'll add some technical detail and give a walkthrough of the sample project. &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Add Generated Items &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Run the Add generated items recipe from the Guidance Package Manager, or from the context menu of any project in Solution Explorer. The wizard loads to collect settings - in the first page you select the metadata source type, configure the source and select the metadata provider: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030709_1952_CodeGenerat1.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;During generation, the provider will load each of the selected metadata items and provide them as a property which can be accessed in the T4 template. For instance if you use the SQL Server Stored Procedure provider, your T4 script will have a populated SqlCommand object available to use. &lt;/p&gt;
&lt;p&gt;Provided with the basic Guidance package are the following Sources and Providers: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;
    &lt;div&gt;File System &lt;/div&gt;
    &lt;ul&gt;
        &lt;li&gt;
        &lt;div&gt;File source – for using one or more files as metadata &lt;/div&gt;
        &lt;ul&gt;
            &lt;li&gt;XML File provider – for using XML file contents, exposed to the template as an XmlDocument instance &lt;/li&gt;
            &lt;li&gt;Text File provider – for using text file contents, exposed as a string &lt;/li&gt;
            &lt;li&gt;Assembly File provider – for using a .NET assembly, exposed as an Assembly instance &lt;/li&gt;
        &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li&gt;
        &lt;div&gt;Directory source – for using a list of directory contents as metadata &lt;/div&gt;
        &lt;ul&gt;
            &lt;li&gt;File List provider – for using a list of file names, exposed as a List&amp;lt;string&amp;gt; instance &lt;/li&gt;
            &lt;li&gt;Directory provider – for using a directory, exposed as a DirectoryInfo instance &lt;/li&gt;
        &lt;/ul&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Database &lt;/div&gt;
    &lt;ul&gt;
        &lt;li&gt;
        &lt;div&gt;SQL Server Database &lt;/div&gt;
        &lt;ul&gt;
            &lt;li&gt;Query Result provider – for executing a SQL query and exposing the results in a populated DataSet &lt;/li&gt;
            &lt;li&gt;Table provider – for using a table as metadata, exposed as an empty DataTable with the correct structure &lt;/li&gt;
            &lt;li&gt;Stored Procedure provider – for using stored procedures, exposed as a populated SqlCommand object &lt;/li&gt;
        &lt;/ul&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;WSDL &lt;/div&gt;
    &lt;ul&gt;
        &lt;li&gt;
        &lt;div&gt;SOAP source &lt;/div&gt;
        &lt;ul&gt;
            &lt;li&gt;Web Method provider – for using a Web service method, exposed as a MethodInfo object &lt;/li&gt;
            &lt;li&gt;Schema provider – for using the WSDL of the service, exposed as an XmlSchema object &lt;/li&gt;
        &lt;/ul&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you select a provider, it will load a list of all available metadata items, and you select which items you want to run the T4 template against: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030709_1952_CodeGenerat2.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;The item selection is always a simple list displaying the item name – this will be the name of the file, table, Web method etc (an exception is the QueryResult provider which uses this page to capture the SQL query to be executed). &lt;/p&gt;
&lt;p&gt;In the final screen, select the T4 template to use: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030709_1952_CodeGenerat3.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;The file dialog will default to the "Templates" folder of the Guidance package, but you can navigate to any T4 file. If you want to override the output settings from the T4 file, specifying a different target filename, namespace extension or class name you can do it in the additional properties in this step: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030709_1952_CodeGenerat4.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;Finish the wizard and the recipe will iterate over each of the selected items, populating a representation of the metadata and passing it to the T4 template property.  &lt;/p&gt;
&lt;p&gt;&lt;em&gt;T4 Template Properties &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In order to access metadata item information and create the output, your T4 script needs to specify two properties which will be populated using the Guidance PropertyProcessor engine: &lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&amp;lt;#@ property processor="PropertyProcessor" name="MetadataItem" #&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&amp;lt;#@ property processor="PropertyProcessor" name="TemplateConfiguration" #&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;The &lt;em&gt;MetadataItem&lt;/em&gt; property is an object implementing &lt;strong&gt;Sixeyed.CodeGeneration.Metadata.Interfaces.IMetadataItem&lt;/strong&gt;: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030709_1952_CodeGenerat5.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;The underlying &lt;em&gt;Item&lt;/em&gt; property gives you access to the populated metadata item – the object type will depend on the provider, and will be specified in the &lt;em&gt;ItemType&lt;/em&gt; property. The &lt;em&gt;Key&lt;/em&gt; for the item (the name shown in the Select Items wizard page) is available, as is the metadata &lt;em&gt;Provider&lt;/em&gt; which can be used to navigate up to the source. &lt;/p&gt;
&lt;p&gt;The &lt;em&gt;TemplateConfiguration&lt;/em&gt; property allows you to control the output of the template, setting default values for the target file name etc. (which can be overridden in the Select Template wizard page). It's an object of type &lt;strong&gt;Sixeyed.CodeGeneration.Generation.TemplateConfiguration&lt;/strong&gt;: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/030709_1952_CodeGenerat6.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Sample Templates &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The CodeGeneration.Sample Guidance package contains a sample template for each of the metadata providers, demonstrating the type of object they expose and how it can be used. The scripts don't do much other than demonstrate usage, but there are fully-fledged scripts for generating wrappers for SQL Server stored procedures, and configuration sections from text files. The full script for the Table provider sample makes straightforward use of the underlying DataTable object: &lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;template&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; language=&lt;/span&gt;"&lt;span style="color: blue;"&gt;C#&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;property&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; processor=&lt;/span&gt;"&lt;span style="color: blue;"&gt;PropertyProcessor&lt;/span&gt;"&lt;span style="color: red;"&gt; name=&lt;/span&gt;"&lt;span style="color: blue;"&gt;MetadataItem&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;property&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; processor=&lt;/span&gt;"&lt;span style="color: blue;"&gt;PropertyProcessor&lt;/span&gt;"&lt;span style="color: red;"&gt; name=&lt;/span&gt;"&lt;span style="color: blue;"&gt;TemplateConfiguration&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;assembly&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; name=&lt;/span&gt;"&lt;span style="color: blue;"&gt;System.dll&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;assembly&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; name=&lt;/span&gt;"&lt;span style="color: blue;"&gt;System.Data.dll&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;assembly&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; name=&lt;/span&gt;"&lt;span style="color: blue;"&gt;System.Xml.dll&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;assembly&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; name=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Sixeyed.CodeGeneration.dll&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;import&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; namespace=&lt;/span&gt;"&lt;span style="color: blue;"&gt;System.Data&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#@&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: brown;"&gt;&lt;strong&gt;import&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red;"&gt; namespace=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Sixeyed.CodeGeneration.Generation&lt;/span&gt;"&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#&lt;/span&gt;&lt;span style="color: midnightblue; background-color: silver;"&gt; PrepareOutput(); &lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: gray; font-family: Courier New; font-size: 10pt;"&gt;/* &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: gray;"&gt;Table&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: gray;"&gt;name&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: gray;"&gt;(from&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: gray;"&gt;metadata):&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#=&lt;/span&gt;&lt;span style="color: midnightblue; background-color: silver;"&gt; MetadataItem.Key &lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: gray;"&gt;Table&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: gray;"&gt;name&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: gray;"&gt;(from&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: gray;"&gt;table):&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#=&lt;/span&gt;&lt;span style="color: midnightblue; background-color: silver;"&gt; dataTable.TableName &lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: gray; font-family: Courier New; font-size: 10pt;"&gt;Columns: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#&lt;/span&gt;&lt;span style="color: midnightblue; background-color: silver;"&gt; foreach (DataColumn column in dataTable.Columns) &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: midnightblue; background-color: silver;"&gt;    &lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt;&lt;/span&gt;&lt;span style="color: gray;"&gt;Column&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: gray;"&gt;Name:&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#=&lt;/span&gt;&lt;span style="color: midnightblue; background-color: silver;"&gt; column.ColumnName &lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: red;"&gt;      &lt;/span&gt;&lt;span style="color: gray;"&gt;Data&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="color: gray;"&gt;Type:&lt;/span&gt;&lt;span style="color: red;"&gt; 			&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#=&lt;/span&gt;&lt;span style="color: midnightblue; background-color: silver;"&gt; column.DataType &lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;#&lt;/span&gt;&lt;span style="color: midnightblue; background-color: silver;"&gt;} &lt;/span&gt;&lt;span style="background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: gray; font-family: Courier New; font-size: 10pt;"&gt;*/ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt; background-color: yellow;"&gt;&amp;lt;#+ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;private DataTable dataTable &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;    get{ return MetadataItem.Item as DataTable; } &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;} &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;private void PrepareOutput() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;    TemplateConfiguration.ClassName = string.Format("Table_{0}", MemberName.ToPascalCase(MetadataItem.Key, true)); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;    TemplateConfiguration.FileExtension = "cs"; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: midnightblue; font-family: Courier New; font-size: 10pt; background-color: silver;"&gt;} &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt; background-color: yellow;"&gt;#&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;(If you don't already have it, the &lt;a href="http://www.visualt4.com/downloads.html"&gt;T4 Editor Community Edition&lt;/a&gt; from Clarius makes editing templates much easier). &lt;/p&gt;
&lt;p&gt;The directives specify the expected properties, and import the relevant reference assemblies and namespaces. The script provides the &lt;em&gt;dataTable&lt;/em&gt; property to easily access the metadata item as a typed DataTable object. In the &lt;em&gt;PrepareOutput&lt;/em&gt; method (called at the start of the template), the script sets up the target class name and file extension. In this case a target filename is not specified, so the engine will use the class name and file extension for the filename. Note there are some helper methods in &lt;strong&gt;Sixeyed.CodeGeneration.Generation.MemberName&lt;/strong&gt; for preparing valid member names. &lt;/p&gt;
&lt;p&gt;Selecting a single table called Manufacturers for this script generates and adds a file called Table_Manufacturers.cs to the selected project, containing the following output: &lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;/* &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;Table name (from metadata): Manufacturers &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;Table name (from table): Manufacturers &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;Columns: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;Column Name: ManufacturerId &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;      Data Type: System.Int16 &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;Column Name: ManufacturerName &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;      Data Type: System.String &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;Column Name: AvailableFromDate &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;      Data Type: System.DateTime &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;Column Name: AvailableToDate &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;      Data Type: System.DateTime &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: green; font-family: Courier New; font-size: 10pt;"&gt;*/ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Usage &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For ad-hoc code generation, this basic Guidance package lets you specify metadata to execute against a T4 template. For commonly used scripts and standard patterns you can build a custom Guidance package which contains your solution structure, and specific recipes for generating known types of item – for DAL classes, entities, configuration sections, proxies or anything else that is based on external metadata. &lt;/p&gt; &lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/129906.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2009/03/07/code-generation-guidance-package.aspx</guid>
            <pubDate>Sat, 07 Mar 2009 19:51:14 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/129906.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2009/03/07/code-generation-guidance-package.aspx#feedback</comments>
            <slash:comments>12</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/129906.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Quick registration of Package in progress… This may take a while</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2008/10/15/quick-registration-of-package-in-progress-this-may-take-a.aspx</link>
            <description>&lt;p style="text-align: center;"&gt;&lt;span style="font-size: 10pt;"&gt;[Source: &lt;a href="http://geekswithblogs.net/EltonStoneman"&gt;http://geekswithblogs.net/EltonStoneman&lt;/a&gt;] &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The Guidance Automation Extensions Toolkit (see &lt;a href="http://msdn.microsoft.com/en-us/vsts2008/aa718949.aspx"&gt;GAX Toolkit&lt;/a&gt;) gives you this lovely message when you use the "Quick Register" action in your GAX package development. It's true that it can take a while, although it's substantially quicker than the full registration action.  &lt;/p&gt;
&lt;p&gt;When you're in development though, solutions using your GAX package will read the contents from the project's &lt;strong&gt;bin\Debug&lt;/strong&gt;, so you may not need to re-register between builds at all. Experiments with registration types suggest that they need to be used in the following situations: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Full Register&lt;/strong&gt; – needed the first time you register the package, and may be needed following an Unregister if the package has been corrupted or isn't functioning as expected. Takes several minutes and does a variety of interesting things (check Task Manager while it's running); builds the solution and validates package XML before deploying. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Quick Register&lt;/strong&gt; – may take a while, but usually in the order of tens of seconds rather than minutes. Also builds the solution and validates the package XML, but doesn't do the full suite of registration tasks. Not necessary in normal use, although if you've modified the XML it's worth having it validated before trying to use it. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;No registration&lt;/strong&gt; – in dev, the package is read from &lt;strong&gt;bin\Debug&lt;/strong&gt;, so if you're adding or modifying templates, you can just rebuild and they'll be immediately available. Similarly if you change or add to the code in the project or dependencies, close any solutions using the GAX package and rebuild and the changes will take effect when you re-open. Interestingly, if you modify the XML – e.g. to add a new action – you can also just rebuild and not register, and the new action will be listed when you open a solution using the package. If not, disable then re-enable the package, and the new action should appear. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Obviously this only applies in dev, and if you deploy your GAX package using the MSI, you'll need to redeploy in full for changes to take effect. Useful to know though, and may mean your GAX development takes less of a while.&lt;/p&gt; &lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/125850.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2008/10/15/quick-registration-of-package-in-progress-this-may-take-a.aspx</guid>
            <pubDate>Tue, 14 Oct 2008 23:33:47 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/125850.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2008/10/15/quick-registration-of-package-in-progress-this-may-take-a.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/125850.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
