<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Leaning Into Windows : Visual Basic, C#, Code Generation</title><link>http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/C_2300_/Code+Generation/default.aspx</link><description>Tags: Visual Basic, C#, Code Generation</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Open Source</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/13/open-source.aspx</link><pubDate>Wed, 13 Feb 2008 15:31:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1512469</guid><dc:creator>Kathleen</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1512469</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/13/open-source.aspx#comments</comments><description>&lt;p&gt;It’s occurred to me that if you are following this and my DNR TV show a logical reaction would be “OK, so that’s a lot of hot air, where do I get it?” I intend for all of this to be released Open Source, on whichever site s hot when I release it. I hope I’ll start releasing pieces in just a matter of weeks. It will help a lot if it becomes “we” instead of “me”. So, if you’re interested n this stuff and you want to help, let me know and you can get this stuff directly as its rapidly evolving too much to publically post right now. &lt;/p&gt; &lt;p&gt;My current expectation of the order of release: &lt;ul&gt; &lt;li&gt;Metadata interfaces &lt;/li&gt; &lt;li&gt;GenDotNet metadata load&lt;/li&gt; &lt;li&gt;EDMX metadata load&lt;/li&gt; &lt;li&gt;Template infrastructure – what’s needed for the language neutral templates&lt;/li&gt; &lt;li&gt;Simple harness&lt;/li&gt; &lt;li&gt;Activity based harness&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;If you’re interested, you can contact me directly at Kathleen@mvps.org&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1512469" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Isolating Metadata</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/13/isolating-metadata.aspx</link><pubDate>Wed, 13 Feb 2008 15:26:09 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1512464</guid><dc:creator>Kathleen</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1512464</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/13/isolating-metadata.aspx#comments</comments><description>&lt;p&gt;In code generation, metadata is the information about your application, generally about your database and definitions to express your data as business objects. If you use Entity Framework, your metadata is the edmx file which is displayed via the designers. If you’re using CodeSmith, the metadata is more subtle. Metadata can also be about the process itself. CodeBreeze in particular has a very rich set and extensible set of information about your application. &lt;/p&gt; &lt;p&gt;Since metadata itself is data – information - we can store it many ways. I’ve used XML for years. CodeSmith has used a couple of mechanisms including XML. Entity Framework uses XML. Metadata can also come directly from a database, although I think this is a remarkably bad idea and one of my code generation principles is not to do that – you need a level of indirection and isolation surrounding your database.  &lt;p&gt;What I haven’t talked about before how valuable it is to have another layer of indirection between your metadata storage structure – your XML schema – and your templates. In my XSLT templates I could provide this only through a common schema – you can morph your XML into my schema so that’s indirection – right?  &lt;p&gt;No, that’s not really indirection. It’s great to be back in .NET classes with real tools for isolation and abstraction. Now I use a set of interfaces for common metadata constructs such as objects, properties and criteria. I can then offer any number of sets of metadata wrappers that implement these interfaces via a factory.  &lt;p&gt;&amp;nbsp; &lt;p&gt;&lt;a href="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/IsolatingMetadata_769B/MetadataIsolation_2.jpg"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="449" alt="MetadataIsolation" src="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/IsolatingMetadata_769B/MetadataIsolation_thumb.jpg" width="911" border="0" /&gt;&lt;/a&gt;  &lt;p&gt;&amp;nbsp; &lt;p&gt;The template programs only against the interfaces. The template could care less whether I am using entity framework, my own metadata tools, or something entirely different. &lt;b&gt;&lt;i&gt;I can write the same template and use it against Entity Framework’s edmx file or any other metadata format&lt;/i&gt;&lt;/b&gt;. That’s powerful stuff. Especially since you already heard that the template will run against C# or VB. That means in my world the only reason to have more than one set of templates against an architecture like &lt;a href="http://lhotka.net/"&gt;CSLA&lt;/a&gt; is that they are pushing the boundaries and actually doing different things. &lt;p&gt;But if you don’t like this new templating style, you can use classes based on exactly the same interfaces in CodeSmtih (at least) and again free your framework and metadata extraction. You’ll still need VB/C# versions there, but you’re metadata input can use the same interfaces. &lt;p&gt;The interfaces is expressed in sets of classes that know how to load themselves from a data source. Each set uses a different metadata source – different XML structures or other format.  &lt;p&gt;Isolated metadata removes your templates from caring what the metadata source is – beyond being something that could successfully fill a set of classes that implement the data interfaces. This is a very important step and one we need to work together to get right. What do you think I&amp;#39;ve left out of the current design?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1512464" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Design/default.aspx">Design</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>CurrentTypeInfo and the Context Stack</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/12/currenttypeinfo-and-the-context-stack.aspx</link><pubDate>Tue, 12 Feb 2008 15:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1510299</guid><dc:creator>Kathleen</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1510299</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/12/currenttypeinfo-and-the-context-stack.aspx#comments</comments><description>&lt;p&gt;Creating templates requires a lot of access to the thing you’re currently creating. That’s the current output type, which as I discussed in &lt;a href="http://msmvps.com/blogs/kathleen/archive/2008/02/11/two-parallel-entities-metadata-and-info.aspx"&gt;yesterday&lt;/a&gt; I suffix with “Info.” The CurrentTypeInfo is thus what you’re currently outputting. 
&lt;p&gt;&lt;i&gt;I neglected to clarify in that post that the Data and the Info classes are in entirely different assemblies. The Data classes could be used with any .NET generation mechanism, including (at least) XML Literal code generation and CodeSmith. The Info objects are relatively specific to my style of code generation. &lt;/i&gt;
&lt;p&gt;The CurrentTypeInfo may not be the same throughout the file. 
&lt;p&gt;There are a few reasons to combine multiple classes or enums in a file. In some cases, that’s to nest them, and in some cases it’s just to logically combine them in a file. While FxCop has declared them unfashionable, I find nested classes tremendously valuable, especially for organizing Intellisense and keeping well structured classes and naming. If you’re working with nested classes, there is a good chance you’ll need to access not only the current type, but also the encapsulating type. I use a stack for this, and give control of pushing and popping TypeInfo objects from the stack to the templates themselves. 
&lt;p&gt;&lt;a href="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/CurrentTypeInfoandtheContextStack_7B45/TemplateInheritanceDotNetBase3_2.jpg"&gt;&lt;img style="BORDER-RIGHT:0px;BORDER-TOP:0px;BORDER-LEFT:0px;BORDER-BOTTOM:0px;" height="369" alt="TemplateInheritanceDotNetBase3" src="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/CurrentTypeInfoandtheContextStack_7B45/TemplateInheritanceDotNetBase3_thumb.jpg" width="215" border="0" /&gt;&lt;/a&gt; 
&lt;p&gt;The base item on the stack is the current outer most class in the current file. Once you’ve pulled a class off the stack, such as by popping the base and adding a new base TypeInfo, you can’t access the previous version unless you’ve saved it. 
&lt;p&gt;Here’s where you see the flaw I mentioned yesterday – these classes could be in separate namespaces, and I don’t allow for that – yet. I’ll fix it later. 
&lt;p&gt;Remember the TypeInfo is the thing you’re outputting. The entity definition it’s built from is ObjectData in my semantics. 
&lt;p&gt;The stack is an extremely useful construct for this scenario. You have quick access to information about the class you’re currently outputting. You’ll frequently need this for type information and perhaps calling shared/static methods. You don’t want to recreate its name every time you use it because that would be redundant and hard to maintain. You can also access any of the containing classes, which again is useful in defining types and calling shared/static methods. 
&lt;p&gt;While I haven’t done this in CodeSmith, I expect this technique to be viable there. I’m not sure on other platforms, but it’s not specific to XML literal code generation. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1510299" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Two Parallel Entities - Metadata and Info</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/11/two-parallel-entities-metadata-and-info.aspx</link><pubDate>Mon, 11 Feb 2008 17:08:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1508491</guid><dc:creator>Kathleen</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1508491</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/11/two-parallel-entities-metadata-and-info.aspx#comments</comments><description>&lt;p&gt;One of the confusing things about templating is that you are writing two programs simultaneously and there is no way around it. My brilliant son may write a templating language for a class project, and this is exactly what he wants to address – that and the issue of escaping. You can’t avoid it, he just thinks they should look different – I’m hoping he doesn’t write one in Magyar. 
&lt;p&gt;One of the programs you’re writing (or maintaining) is the template program. There is logic in any non-trivial template, regardless of the template style. The other program is the one you’re outputting that will eventually run on your clients computer. In ASP.NET style templates, the output program is the overall template, and the logic is inserted. In XSLT and XML literal generation, the logic of the template program is the overall code and the output template is nested inside. 
&lt;p&gt;You are also working with two sets of data – the metadata you’re using as source and what you’re currently outputting. I call the elements in the XML I use as source metadata for .NET templates Object and Property for clarity in the XML. If I called them that in the templates, I’d encounter great confusion between the object definition in metadata and the class I am outputting. That’s particularly painful when it comes to properties. 
&lt;p&gt;I solve this by calling suffixing all metadata with the word “Data”. Thus I have ObjectData, PropertyData, CriteriaData, etc. Each of these classes contains the metadata on the corresponding item. I might have an ObjectData for a Customer that had a PropertyData for FirstName. The PropertyData would include things like the maximum length of the field and its caption. 
&lt;p&gt;I also need to describe the output – at least the way I’m building templates. I need information about the file I’m creating, the type I’m creating, and in certain locations in the template, the property, function, constructor, etc I’m creating. I identify these by suffixing them with the word “Info”. Thus I have a ClassInfo, PropertyInfo, FunctionInfo, etc. I do not have a CriteriaInfo because I am never outputting a .NET thing called a Criteria. It’s strictly metadata for .NET features. 
&lt;p&gt;In the template design I’m describing in this series, the DotNetBase class contains information on the file being output. To be picky, the namespace can actually be associated with part of a file, and I may add this flexibility, but I don’t do that very often in business code, so I have included namespaces at the file level.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/TwoParallelEntitiesMetadataandInfo_8EA0/TemplateInheritanceDotNetBase2_2.jpg"&gt;&lt;img style="BORDER-RIGHT:0px;BORDER-TOP:0px;BORDER-LEFT:0px;BORDER-BOTTOM:0px;" height="369" alt="TemplateInheritanceDotNetBase2" src="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/TwoParallelEntitiesMetadataandInfo_8EA0/TemplateInheritanceDotNetBase2_thumb.jpg" width="215" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Regardless of the template mechanism you use, you need to maintain a clear separation between the template logic and the output logic, and between the input metadata and state about what you’re creating. 
&lt;p&gt;Next post: CurrentTypeInfo and the Context Stack&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1508491" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Inheritance and Templates</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/11/inheritance-and-templates.aspx</link><pubDate>Mon, 11 Feb 2008 16:25:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1508442</guid><dc:creator>Kathleen</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1508442</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/11/inheritance-and-templates.aspx#comments</comments><description>&lt;p&gt;One of the most valuable things about templates written in .NET code of any style is the ability to use inheritance. This is classic inheritance where local state allows you to push functionality into base class methods that would become cumbersome and have excess dependencies if treated as external utility methods. 
&lt;p&gt;Inheritance also allows polymorphism, which is nothing more than a big word for exchangeability – OK, that’s actually a bigger word. Templates are called by something. Life is simpler and harnesses practical if that something is known and predictable, thus it’s logical to have an interface in a common location as a contract to the template interface. If the base class implements this interface and provides functionality via MustInherit/abstract members, there’s further capacity for evolution. 
&lt;p&gt;&lt;a href="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/InheritanceandTemplates_846E/TemplateInheritanceHierarchy_2.jpg"&gt;&lt;img style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" height="736" alt="TemplateInheritanceHierarchy" src="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/InheritanceandTemplates_846E/TemplateInheritanceHierarchy_thumb.jpg" width="623" border="0" /&gt;&lt;/a&gt; 
&lt;p&gt;There are three assemblies involved. The template interface is in a common assembly available to all other assemblies. The base classes are in a support assembly which can be reused across many template sets. The templates themselves are in a separate assembly. For now, I have all templates associated with a project in one assembly, but I may change that to isolate the SQL and the .NET templates. In any case, these template assemblies are sets of templates that work together. 
&lt;p&gt;Inheritance let’s you push common functionality into the base class. Now that we have extension methods they offer an additional mechanism to remove common functionality from the leaf class. I know Scott Hanselman has said he’ll cut off the pinkies of anyone who uses extension methods on classes you own, and I’ll show you when I get to that in a few days why I disagree (although it’s in the DRN TV show). But that explains why my base classes are focused on state more than functionality. The key state issue is what you’re currently working on. In a template, state is metadata. In a .NET template, the important metadata is the definition for the entity you’re currently creating. In my templates, the ObjectData member of the DotNetBase contains this information. 
&lt;p&gt;&lt;a href="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/InheritanceandTemplates_846E/TemplateInheritanceDotNetBase_2.jpg"&gt;&lt;img style="BORDER-RIGHT:0px;BORDER-TOP:0px;BORDER-LEFT:0px;BORDER-BOTTOM:0px;" height="369" alt="TemplateInheritanceDotNetBase" src="http://msmvps.com/blogs/kathleen/WindowsLiveWriter/InheritanceandTemplates_846E/TemplateInheritanceDotNetBase_thumb.jpg" width="215" border="0" /&gt;&lt;/a&gt; 
&lt;p&gt;Stay tuned for the distinction between the input data you’re working on and the thing you’re creating, which explains some of those other members.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1508442" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>.NET Template Organization</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/10/net-template-organization.aspx</link><pubDate>Sun, 10 Feb 2008 23:55:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1507240</guid><dc:creator>Kathleen</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1507240</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/10/net-template-organization.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, now that you know where I’m going with this – language neutral templates – I want to step back to the basics. Even if you don’t want to build language neutral templates, there are things to learn along the way about making good XML literal templates, and why this approach might be better than your current code gen mechanism. Note, the examples in this post are NOT language neutral. Not surprisingly, there are specific requirements for language neutral templates and I want to show basic templating with XML literals, then the language neutral templates. 
&lt;p&gt;If you look at the XML literal sample I posted a few days ago you’ll notice that the entire contents of the output DataPortalFetch method is created within the template method “MemberDataPortalFetch.” This provide important organization as the most common challenging task in code generation is “I have a problem in my output code right here, how do I find where that is in the template. In a simple template this isn’t too hard, but in more complex templates such as CSLA it can be quite challenging. 
&lt;p&gt;Creating templates with an extremely predictable structure is very valuable in creating maintainable templates. To start with each template should have a one to one correspondence with an output class. 
&lt;p&gt;Within this class, the mechanism of the predictable structure is one of the primary differences from codes that are code with template segments (XML literal code generation) and templates with code segments (ASP.NET style template). In an ASP.NET template, the template must parallels the output and this organizes the template. In an XML literal template, you provide the organization with Visual Studio then providing navigation. Code is organized my regions, nested classes and member. Each is its own method preceded by Region, NestedClass or Member. This organizes the template. The entry points create a hierarchy working down to the local code (navigation mechanism #1): 
&lt;p&gt;&amp;nbsp;&amp;nbsp; Protected Overrides Function GenerateFile() As String&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return _&lt;br /&gt;&amp;lt;code&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;amp;lt;Serializable()&amp;gt; _&lt;br /&gt;Public Class &amp;lt;%= mObjectData.ClassName %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; Inherits BusinessBase(Of &amp;lt;%= mObjectData.ClassName %&amp;gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= RegionBusinessMethods() %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= RegionValidationRules() %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= RegionAuthorizationRules() %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= RegionFactoryMethods() %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= RegionDataAccess() %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= RegionExists() %&amp;gt;&lt;br /&gt;End Class&lt;br /&gt;&amp;lt;/code&amp;gt;.Value&lt;br /&gt;&amp;nbsp;&amp;nbsp; End Function 
&lt;p&gt;And 
&lt;p&gt;#Region &amp;quot;Business Methods&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp; Private Function RegionBusinessMethods() As String&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return _&lt;br /&gt;&amp;lt;code&amp;gt;&lt;br /&gt;#Region &amp;quot; Business Methods &amp;quot; 
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= From prop In mObjectData.Properties Select MemberPropertyFields(prop) %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= From child In mObjectData.Children Select MemberChildFields(child) %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= From prop In mObjectData.Properties Select MemberPropertyAccess(prop) %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= From child In mObjectData.Children Select MemberChildAccess(child) %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= MemberIsValid() %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= MemberIsDirty() %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;%= MemberGetId() %&amp;gt; 
&lt;p&gt;#End Region&lt;br /&gt;&amp;lt;/code&amp;gt;.Value 
&lt;p&gt;&amp;nbsp;&amp;nbsp; End Function 
&lt;p&gt;The carefully named methods also allow you to use alphabetical tools in Visual Studio including the combo box in the upper right of the editor and a class diagram (navigation mechanism #2) which works only because you can predict the name of the member you want from the name of the output member and no other members begin with “Member”, “Region” or “NestedClass” 
&lt;p&gt;The third navigation approach is that the template matches the structure of the output as closely as practical. Thus if the output has a region names “Business Methods” the template does as well. The order of items in the template is top to bottom closely paralleling the order of the output. This allows you to cruise down in the file. 
&lt;p&gt;Template organization is the first step to great templates. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1507240" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>The Punch Line</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/10/the-punch-line.aspx</link><pubDate>Sun, 10 Feb 2008 23:21:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1507199</guid><dc:creator>Kathleen</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1507199</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/10/the-punch-line.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I mentioned a few days ago that there was a punch line for the XML Literal Code Generation. I planned to unveil this slowly, but it just sprung out of the box when Carl posted episode #102 (which I thought was due for &lt;b&gt;&lt;i&gt;next&lt;/i&gt;&lt;/b&gt; Friday. 
&lt;p&gt;And I’m afraid that I need to add that I was sick during the taping and my brain running at half capacity. If anything isn’t clear, please let me know. 
&lt;p&gt;No matter. 
&lt;p&gt;You get to hear sooner. 
&lt;p&gt;I’ll be unveiling the details in about the same time frame, so you’ll have the big picture by next week. 
&lt;p&gt;So, the drumroll please… 
&lt;p&gt;&lt;u&gt;&lt;em&gt;I can create excellent readable templates that output code in Visual Basic or C# - no CodeDOM involved.&lt;/em&gt;&lt;/u&gt; 
&lt;p&gt;I’ll show you how to do that. Watch for more here. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1507199" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>XML Literal Code Genaration - Code again again</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/10/xml-literal-code-genaration-code-again-again.aspx</link><pubDate>Sun, 10 Feb 2008 16:53:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1506692</guid><dc:creator>Kathleen</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1506692</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/10/xml-literal-code-genaration-code-again-again.aspx#comments</comments><description>&lt;p&gt;Crap. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;For now, I&amp;#39;m just removing the coloring. Paste this into VS for coloring. It&amp;#39;s much prettier:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; Private Function MemberDataPortalFetch() As String&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39; TODO: Add special handing for timestamp&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return _&lt;br /&gt;&amp;lt;code&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; Private Overloads Sub DataPortal_Fetch(ByVal criteria As Criteria)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Using cn As New SqlConnection(&amp;lt;%= mObjectData.ConnectionStringName %&amp;gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cn.Open()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Using cm As SqlCommand = cn.CreateCommand&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cm.CommandType = CommandType.StoredProcedure&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cm.CommandText = &amp;quot;get&amp;lt;%= mObjectData.ClassName %&amp;gt;&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;%= From prop In mObjectData.PrimaryKeys Select _&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;code&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cm.Parameters.AddWithValue(&amp;quot;@&amp;lt;%= prop.Name %&amp;gt;&amp;quot;, criteria.&amp;lt;%= prop.Name %&amp;gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/code&amp;gt; %&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Using dr As New SafeDataReader(cm.ExecuteReader)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dr.Read()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; With dr&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;%= From prop In mObjectData.Properties Select _&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;code&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m&amp;lt;%= prop.Name %&amp;gt; = &amp;lt;%= GetReadMethod(prop) %&amp;gt;(&amp;quot;&amp;lt;%= prop.Name %&amp;gt;&amp;quot;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/code&amp;gt;.Value %&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39; load child objects&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .NextResult()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;%= From child In mObjectData.Children Select _&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;code&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m&amp;lt;%= child.Name %&amp;gt; = &amp;lt;%= child.Name %&amp;gt; .Get&amp;lt;%= child.Name %&amp;gt; (dr)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/code&amp;gt;.Value %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End With&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Using&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Using&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Using&lt;br /&gt;&amp;nbsp;&amp;nbsp; End Sub&lt;br /&gt;&amp;lt;/code&amp;gt;.Value&lt;br /&gt;&amp;nbsp;&amp;nbsp; End Function&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1506692" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>XML Literal Code Generation - Code again</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/10/xml-literal-code-generation-code-again.aspx</link><pubDate>Sun, 10 Feb 2008 16:32:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1506685</guid><dc:creator>Kathleen</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1506685</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/10/xml-literal-code-generation-code-again.aspx#comments</comments><description>&lt;p&gt;OK, that code listing got friend on load. Let me try again.&lt;/p&gt;&amp;nbsp;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;Private&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Function&lt;/span&gt; MemberDataPortalFetch() &lt;span style="COLOR:blue;"&gt;As&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;String&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;Return&lt;/span&gt; _&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#6464b9;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#844646;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;code&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#6464b9;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;Private Overloads Sub DataPortal_Fetch(ByVal criteria As Criteria)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;Using cn As New SqlConnection(&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; mObjectData.ConnectionStringName &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;cn.Open()&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;Using cm As SqlCommand = cn.CreateCommand&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;cm.CommandType = CommandType.StoredProcedure&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;cm.CommandText = &amp;quot;get&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; mObjectData.ClassName &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;From&lt;/span&gt; prop &lt;span style="COLOR:blue;"&gt;In&lt;/span&gt; mObjectData.PrimaryKeys &lt;span style="COLOR:blue;"&gt;Select&lt;/span&gt; _&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;cm.Parameters.AddWithValue(&amp;quot;@&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; prop.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&amp;quot;, criteria.&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; prop.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;Using dr As New SafeDataReader(cm.ExecuteReader)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;dr.Read()&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;With dr&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;From&lt;/span&gt; prop &lt;span style="COLOR:blue;"&gt;In&lt;/span&gt; mObjectData.Properties &lt;span style="COLOR:blue;"&gt;Select&lt;/span&gt; _&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;m&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; prop.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="COLOR:#555555;"&gt;= &lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; GetReadMethod(prop) &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;(&amp;quot;&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; prop.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&amp;quot;)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;.Value &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&amp;#39; load child objects&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;.NextResult()&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;From&lt;/span&gt; child &lt;span style="COLOR:blue;"&gt;In&lt;/span&gt; mObjectData.Children &lt;span style="COLOR:blue;"&gt;Select&lt;/span&gt; _&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;m&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; child.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="COLOR:#555555;"&gt;= &lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; child.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;.Get&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; child.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="COLOR:#555555;"&gt;(dr)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#555555;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;.Value &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End With&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End Using&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End Using&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End Using&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End Sub&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#6464b9;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#844646;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;code&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#6464b9;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;.Value&lt;/span&gt;&lt;span style="FONT-SIZE:12pt;FONT-FAMILY:&amp;#39;Times New Roman&amp;#39;,&amp;#39;serif&amp;#39;;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;End&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:12pt;FONT-FAMILY:&amp;#39;Times New Roman&amp;#39;,&amp;#39;serif&amp;#39;;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;mso-ansi-language:EN;"&gt;&lt;/span&gt; 
&lt;p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1506685" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>XML Literal Code Generation</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/08/xml-literal-code-generation.aspx</link><pubDate>Fri, 08 Feb 2008 17:20:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1503666</guid><dc:creator>Kathleen</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1503666</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/08/xml-literal-code-generation.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;You must use VB for XML Literal Code Generation. Sorry, that’s life. I don’t have a crystal ball on this, but for now even if you’re a C# programmer you’ve got to suck it up and use VB. The code you output can be VB or C# however, but the template itself has to be written in VB. If you’re allergic to VB, get shots. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;So, what does a microcosmic view of a XML literal template look like? I’ve translated a section of a &lt;/font&gt;&lt;a href="http://www.csla.net/"&gt;&lt;font face="Calibri" color="#0000ff" size="3"&gt;CSLA&lt;/font&gt;&lt;/a&gt;&lt;font face="Calibri" size="3"&gt; template. CSLA is Rocky Lhotka’s architecture and this is a version 2.1 because I think it clarifies the template process:&lt;/font&gt;&lt;/p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;Private&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Function&lt;/span&gt; MemberDataPortalFetch() &lt;span style="COLOR:blue;"&gt;As&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;String&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;Return&lt;/span&gt; _&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#6464b9;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#844646;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;code&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#6464b9;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;Private Overloads Sub DataPortal_Fetch(ByVal criteria As Criteria)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;Using cn As New SqlConnection(&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; mObjectData.ConnectionStringName &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;cn.Open()&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;Using cm As SqlCommand = cn.CreateCommand&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;cm.CommandType = CommandType.StoredProcedure&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;cm.CommandText = &amp;quot;get&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; mObjectData.ClassName &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;From&lt;/span&gt; prop &lt;span style="COLOR:blue;"&gt;In&lt;/span&gt; mObjectData.PrimaryKeys &lt;span style="COLOR:blue;"&gt;Select&lt;/span&gt; _&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;cm.Parameters.AddWithValue(&amp;quot;@&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; prop.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&amp;quot;, criteria.&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; prop.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;BACKGROUND:yellow;COLOR:#555555;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-highlight:yellow;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;Using dr As New SafeDataReader(cm.ExecuteReader)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;dr.Read()&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;With dr&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;From&lt;/span&gt; prop &lt;span style="COLOR:blue;"&gt;In&lt;/span&gt; mObjectData.Properties &lt;span style="COLOR:blue;"&gt;Select&lt;/span&gt; _&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;m&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; prop.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="COLOR:#555555;"&gt;= &lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; GetReadMethod(prop) &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;(&amp;quot;&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; prop.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&amp;quot;)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;.Value &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;BACKGROUND:yellow;COLOR:#555555;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;mso-highlight:yellow;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;&amp;#39; load child objects&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;.NextResult()&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;From&lt;/span&gt; child &lt;span style="COLOR:blue;"&gt;In&lt;/span&gt; mObjectData.Children &lt;span style="COLOR:blue;"&gt;Select&lt;/span&gt; _&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;m&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; child.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="COLOR:#555555;"&gt;= &lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; child.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="COLOR:#555555;"&gt;.Get&lt;span style="BACKGROUND:yellow;mso-highlight:yellow;"&gt;&amp;lt;%=&lt;/span&gt;&lt;/span&gt; child.Name &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="COLOR:#555555;"&gt;(dr)&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#844646;"&gt;code&lt;/span&gt;&lt;span style="COLOR:#6464b9;"&gt;&amp;gt;&lt;/span&gt;.Value &lt;span style="BACKGROUND:yellow;COLOR:#555555;mso-highlight:yellow;"&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End With&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End Using&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End Using&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End Using&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:#555555;"&gt;End Sub&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#6464b9;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#844646;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;code&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#6464b9;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;.Value&lt;/span&gt; 
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;span style="FONT-SIZE:10pt;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;End&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;This is .NET code, which you can see because the template output is inside a .NET function named MemberDataPortalFetch which returns a string constructed with XML literals. By offsetting with XML literals, the code of the function is easily seen – it’s in gray. All of the gray code will be in the output, none of the yellow, blue or black code will be in the output, although it will certainly affect the output. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Where replacements are necessary, XML literals have “embedded expressions” which I have the habit of calling “expression holes.” I’ll talk in another post about what mObjectDatais, but an embedded expression can contain whatever expression you need. An expression is something that returns a value within a single line. So, you can call methods and properties, but you can’t call a subroutine. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Embedded expressions can contain LINQ as shown in the third embedded expression. Here we want to add parameters for all the primary keys. &lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;Within the LINQ Select clause, I can use any string. Including the nested code block creates a more readable template and consistency, among other things.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;A quick glance may leave you thinking that this is just a variation of the ASP.NET style template syntax used by CodeSmith, CodeBreeze, MyGeneration and others. However, it’s quite different. To begin with its organized into members of a template class. Then, the logic is expressed in expressions, not direct template logic. Finally, you can nest back and forth between output text and code to any depth you require. The code blocks within the LINQ statements above contain embedded expressions. These embedded expressions could be further LINQ statements with further code blocks, etc. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;I think there are right and wrong ways to build templates with XML literals. I’ll spend the next couple of posts talking about template organization and metadata handling. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1503666" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Let’s Talk Templates</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/07/let-s-talk-templates.aspx</link><pubDate>Thu, 07 Feb 2008 22:07:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1501999</guid><dc:creator>Kathleen</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1501999</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/07/let-s-talk-templates.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Code generation templates have several competing pressures – they need to be easy to use and they need to be powerful. They need to be flexible but encourage best practices. If you ever say “my templates got me started then I had to customize them” you’re templating can be better. I’m not aware of any situation where you can’t isolate the handcrafted code from the generated code sufficiently to keep code generation active for the entire life of your application. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;When I say full life cycle, I mean from initial prototypes to finally pulling the switch in a decade. Yep a decade. Code generation should aim for evolution and extremely long project life cycles. The metadata of the project can far outlive the technology, even outlive the database. That requires a deep commitment to code generation, and if you don’t have that commitment, the flip side is that code generation can pay back today. At that moment when it feels easier to pull a file out of code generation, or to repeat a similar block of code in two places instead of pushing it into your code gen templates, that’s where the commitment comes in. With or without it, you get payback; it’s just greater the deeper your commitment is to the metadata and templates. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;My current client pushes me because he is even more committed to the decade long lifecycle based on code gen than I am. And he’s right. Every time he’s pushed to get something into templates or do code gen better, it’s taken less work and gotten us further in the short term than I expected. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;What if you could combine the simplicity of CodeSmith with the power of XSLT?&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;And what if you could do it primarily in a language and architecture you already know, or should be learning anyway?&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Interested?&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;This is the first post in a blog series to present this templating style. I also covered in a.NET Rocks show I recorded yesterday. I’m very excited about it, but I want to introduce the basics before I tell you the real punch line. This template style is the best way to generate code today and it’s based entirely on tools you’ve got on your desktop right now. &lt;/font&gt;&lt;/p&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;Look for more here and in the .NET Rocks TV episode scheduled to appear Feb. 15&lt;sup&gt;th&lt;/sup&gt;. The beautiful thing about the techniques I’ll show is that you can smoothly transition from simple to complex templates dialing in the exact complexity appropriate for your organization and application. &lt;i style="mso-bidi-font-style:normal;"&gt;And, just wait for the punch line.&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1501999" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Code+Generation/default.aspx">Code Generation</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/C_2300_/default.aspx">C#</category></item></channel></rss>