<?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</title><link>http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx</link><description>Tags: Visual Basic</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>0</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>Code for DNR TV # 97 and #98 Sample Code</title><link>http://msmvps.com/blogs/kathleen/archive/2008/02/10/code-for-dnr-tv-97-and-98-sample-code.aspx</link><pubDate>Sun, 10 Feb 2008 23:14:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1507190</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=1507190</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/02/10/code-for-dnr-tv-97-and-98-sample-code.aspx#comments</comments><description>&lt;p&gt;Sometimes I drop the ball and I did on getting these samples posted. Note that this is for the two episodes I did on 3.5 languages. I think these episodes are a good run through of the features in both languages. The title wound up with the word &amp;quot;Compare&amp;quot; in the title. I&amp;#39;m not sure I really compare them, beyond seeing them side by side, which I think is useful to understand the underlying mechanisms.&lt;/p&gt;
&lt;p&gt;You can get the code &lt;a href="http://gendotnet.com/Downloads/DNRTVNET35LanguageEnhancements/tabid/659/Default.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I will not be posting code for the code generation episode which is episode #102. That code was too transitory for me to want to release. I will be releasing similar code in my blog over the next week or so.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1507190" 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/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><item><title>DNR TV on .NET 3.5 Languages - Part 1 Posted</title><link>http://msmvps.com/blogs/kathleen/archive/2008/01/18/dnr-tv-on-net-3-5-languages-part-1-posted.aspx</link><pubDate>Fri, 18 Jan 2008 19:55:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1469225</guid><dc:creator>Kathleen</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1469225</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/01/18/dnr-tv-on-net-3-5-languages-part-1-posted.aspx#comments</comments><description>&lt;p&gt;Check out &lt;a class="" href="http://www.dnrtv.com/default.aspx?showNum=97"&gt;.NET Rocks TV this week&lt;/a&gt; for the first of two parts on .NET 3.5 languages - that&amp;#39;s right C# 3.0 and VB 9 together.&amp;nbsp; It makes sense since most features cross over, and where they don&amp;#39;t you&amp;#39;ll want a handle on the differences. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1469225" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</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>Why You Care About System.AddIn</title><link>http://msmvps.com/blogs/kathleen/archive/2008/01/03/why-you-care-about-system-addin.aspx</link><pubDate>Thu, 03 Jan 2008 19:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1435614</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=1435614</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/01/03/why-you-care-about-system-addin.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;When I was fighting with AppDomains to support XML Linq code generation in my new Workflow based code generator, Bill McCarthy said “Hey did you look at System.AddIn” and I said “No, silly I’m not writing add-ins.” &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Well, a few months later, I’m still trying to make it work, and have come to think it’s worth the trouble. So, first, what System.AddIn namespace offers, then why it’s so painful, then what I’m doing to fix your pain. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Simply put, System.AddIn provides abstracted/isolated app domain access. AppDomains are the boundary at which some security stuff happens, and the unit which must be unloaded as a group. You can load individual assemblies into an app domain, but to unload them, you need to unload the entire app domain. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;There are a few scenarios where this is important – sandboxing code you’re running as a plug-in to your application being the one the designers had in mind. I want to use it so I can load my code generator and have it recognize changes in .NET assemblies that are generating code. With my first tool, I never solved this problem because I didn’t think brute force code generation prior to XML literals in Visual Basic made very much sense. You had a lot of the problems with XSLT (whitespace) and a nearly complete inability to search your templates (since we cannot search separately in quoted text. XML literal code generation is the best way yet to generate code – as powerful as XSLT and as easy as CodeSmith. Anyway, I can get carried away on that – it’s why I was willing to invest heavily in System.AddIn.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Along the way, I gained great respect for the complex model that supplies isolation/abstraction. If you’ve ever played&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;with plug-ins you know that the first version of your app and its plug-ins is OK, but keeping things in sync while multiple synergistic applications evolve is nearly impossible. The isolation model means the host only speaks to an adapter, and the add-in only needs to speak to an adapter. The adapter’s functionality and the contract can change in whatever manner is needed. This model, combined with the app domain management may lead System.AddIn to have an important role in your application if your application needs to provide variants for individual clients. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Hopefully you have a good idea what sorts of things clients are going to want to customize, and you place this into an API you hit via the add-in model. If you got it 75% correct out of the chute, it would be a miracle, so the capacity for change built into the isolation model is what actually makes this work &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Literally, you load code on the fly, with whatever security limitations you want, with the ability to unload at your convenience, and pick the correct code from what’s available in a specific directory location. Cool huh!&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;In WinForms, the WinForms threading model prohibits UI’s in the add-in. I understand this is fixed in WPF, although I haven’t yet written a WPF add-in user interface.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;So, now that you have some idea why System.AddIn is worth the trouble, why is it so painful. How could I have possibly spent so long getting it running in a sample (I just output a single quoted string right now). To provide the isolation there is a minimum of seven projects/assemblies involved. These must be deployed in a very specific directory structure for the AddIn system to find the pieces it needs when it needs it. Then there is the error reporting problem – I’ve blogged about a particularly nasty “The target application domain has been unloaded” error.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;So, once you hold your mouth just right, and all your code is perfect, it’s cool. But how many of you right perfect code? And what’s this about an easy maintenance model if you have to change SEVEN assemblies to alter the API. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;I’m working on an article and tool for my column in Visual Studio Magazine that will take either metadata for the API, or the interface and build the simple pass through model. This gets you started. Later when you have interface changes, the isolation model pays for itself, but at that point you understand what’s happening. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;It’s going to be a pretty cool example of the “overwrite until edited” mode that my tool supports. Before I’ve used this for editable files that were pretty much empty. Now, I want to separate changes due to metadata changes – that could be significant – from those for actual mapping you did in the adapters. With luck partial methods will lead to a pretty robust set of code you can alter as you need, while still generating the main API stream. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;I find it very cool to see so many fragments coming together. &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=1435614" 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/Sytem.AddIn/default.aspx">Sytem.AddIn</category></item><item><title>System.Addin “The target application domain has been unloaded”</title><link>http://msmvps.com/blogs/kathleen/archive/2008/01/03/system-addin-the-target-application-domain-has-been-unloaded.aspx</link><pubDate>Thu, 03 Jan 2008 19:29:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1435612</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=1435612</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2008/01/03/system-addin-the-target-application-domain-has-been-unloaded.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;I have just escaped an Alice in Wonderland type maze with System.AddIn namespace. It’s a bit of a nightmare to create the plumbing for an add-in so stay tuned in Visual Studio Magazine for a column on how to generate this so you only do the logical work &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;span style="mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font face="Calibri" size="3"&gt;a)&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face="Calibri" size="3"&gt;Define the add-in API&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="MARGIN:0in 0in 10pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;span style="mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font face="Calibri" size="3"&gt;b)&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face="Calibri" size="3"&gt;Write the add-in&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;If you have created one of these in .NET 3.5 you know how tremendously painful it can be. The particular gotcha that I spent numerous days spread over the last three months is that the host adapter much set the contract handle:&lt;/font&gt;&lt;/p&gt;&lt;font face="Calibri" size="3"&gt;&amp;nbsp;&lt;/font&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; _handle &lt;span style="COLOR:blue;"&gt;As&lt;/span&gt; System.AddIn.Pipeline.ContractHandle&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;&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; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;Public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Sub&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;New&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;ByVal&lt;/span&gt; contract &lt;span style="COLOR:blue;"&gt;As&lt;/span&gt; ILinqGenerator)&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;Me&lt;/span&gt;.contract = contract&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;_handle = &lt;span style="COLOR:blue;"&gt;New&lt;/span&gt; System.AddIn.Pipeline.ContractHandle(contract)&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:blue;"&gt;End&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;font face="Calibri" size="3"&gt;&amp;nbsp;&lt;/font&gt; 
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Now, you might be like me and look at that line of code and say “Hey, no one anywhere is using the _handle variable, so why not just drop it.” That would be consistent with the fact the same sample has numerous Friend methods that are never used. Heck, FxCop is even going to tell me to get rid of this line of code.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;However, it’s required. Without this line of code, you get the error “The target application domain has been unloaded.” &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;But I said I spent days on this, over months which meant I kept coming back its fair to ask why? But that’s the subject for another post. &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=1435612" 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/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Sytem.AddIn/default.aspx">Sytem.AddIn</category></item><item><title>KB Article on VB Compiler Bug is Posted</title><link>http://msmvps.com/blogs/kathleen/archive/2007/12/14/kb-article-on-vb-compiler-bug-is-posted.aspx</link><pubDate>Fri, 14 Dec 2007 22:11:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1397559</guid><dc:creator>Kathleen</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/kathleen/rsscomments.aspx?PostID=1397559</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2007/12/14/kb-article-on-vb-compiler-bug-is-posted.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;The VB team posted the KB article on the VB 9.0 compiler bug I’ve been talking about. It’s at KB945425 an titled “Lines of code may be missing if you compile a solution that has a complex project structure in Visual Studio 2008”&lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1397559" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category></item><item><title>C# 3.0, VB 9.0 and Anonymous Types</title><link>http://msmvps.com/blogs/kathleen/archive/2007/11/22/c-3-0-vb-9-0-and-anonymous-types.aspx</link><pubDate>Thu, 22 Nov 2007 17:57:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1347606</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=1347606</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2007/11/22/c-3-0-vb-9-0-and-anonymous-types.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;&lt;a class="" href="http://www.west-wind.com/WebLog/posts/189329.aspx"&gt;Rick Strahl talks about new C# 3.0 features&lt;/a&gt;, but leaves a few questions…&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Why can’t you change the property values instances of anonymous types?&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;The problem is that instance of anonymous types are hashed by hashing all values. Thus, if values could change, all hashes would have to be updated (impossible with the .NET design) or hashes would not match and all sort of unacceptable side-effects like dictionaries no longer finding their key values.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Visual Basic used a different approach allowing you to identify individual properties as keys with the “Key” keyword. Only these values are readonly, while other properties can be changed.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Why can’t we pass around instance of anonymous types around?&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;We can! That was my Thanksgiving present this morning. &lt;/font&gt;&lt;a href="http://blogs.msdn.com/alexj/archive/2007/11/22/t-castbyexample-t-object-o-t-example.aspx"&gt;&lt;font face="Calibri" size="3"&gt;Check this out…&lt;/font&gt;&lt;/a&gt;&amp;nbsp;from Alex James&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;You do however need to know the structure in the receiving routine, and you’ll also needs some casts so this isn’t going to be quite as fast as a real class. I wanted to test this approach in VB console project:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;Module&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; Module1&lt;/span&gt;&lt;/p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;Sub&lt;/span&gt; Main()&amp;nbsp;&lt;/span&gt; 
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&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;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim&lt;/span&gt; x = &lt;span style="COLOR:blue;"&gt;New&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;With&lt;/span&gt; {.FirstName = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Fred&amp;quot;&lt;/span&gt;, .LastName = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Smith&amp;quot;&lt;/span&gt;}&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof: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;Test(x)&lt;/span&gt;&lt;/p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&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;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.Read()&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp; End&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Private&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Sub&lt;/span&gt; Test(&lt;span style="COLOR:blue;"&gt;Of&lt;/span&gt; T)(&lt;span style="COLOR:blue;"&gt;ByVal&lt;/span&gt; x &lt;span style="COLOR:blue;"&gt;As&lt;/span&gt; T)&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&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;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Dim&lt;/span&gt; y = x.CastByType(&lt;span style="COLOR:blue;"&gt;New&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;With&lt;/span&gt; {.FirstName = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, .LastName = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;})&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&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;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Console.WriteLine(y.firstName &amp;amp; &lt;span style="COLOR:#a31515;"&gt;&amp;quot;, &amp;quot;&lt;/span&gt; &amp;amp; y.LastName)&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;End&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&amp;lt;System.Runtime.CompilerServices.Extension()&amp;gt; _&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Private&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Function&lt;/span&gt; CastByType(&lt;span style="COLOR:blue;"&gt;Of&lt;/span&gt; T)(&lt;span style="COLOR:blue;"&gt;ByVal&lt;/span&gt; x &lt;span style="COLOR:blue;"&gt;As&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Object&lt;/span&gt;, &lt;span style="COLOR:blue;"&gt;ByVal&lt;/span&gt; y &lt;span style="COLOR:blue;"&gt;As&lt;/span&gt; T)&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="COLOR:blue;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Return&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;CType&lt;/span&gt;(x, T)&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;End&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;Function &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="COLOR:blue;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;End&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; &lt;span style="COLOR:blue;"&gt;Module&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&amp;nbsp;&lt;/span&gt; 
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;The trick is that the cast method takes another anonymous type declaration which matches the one we’re working with. The extension method makes the call look more natural, but I don’t think I’d use it in a real project because CastByType now shows up in Intellisense for every type – anonymous or not. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;There’s been some confusion about signatures of anonymous types. These signatures include both name and type, which you can see if you change Test above:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&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;Sub&lt;/span&gt; Test(&lt;span style="COLOR:blue;"&gt;Of&lt;/span&gt; T)(&lt;span style="COLOR:blue;"&gt;ByVal&lt;/span&gt; x &lt;span style="COLOR:blue;"&gt;As&lt;/span&gt; T)&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&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;Dim&lt;/span&gt; y = x.CastByType(&lt;span style="COLOR:blue;"&gt;New&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;With&lt;/span&gt; {.FirstName2 = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, .LastName2 = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;})&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&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;Console.WriteLine(y.firstName2 &amp;amp; &lt;span style="COLOR:#a31515;"&gt;&amp;quot;, &amp;quot;&lt;/span&gt; &amp;amp; y.LastName2)&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&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;Sub&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;font face="Calibri" size="3"&gt;&amp;nbsp;&lt;/font&gt; 
&lt;p&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font face="Calibri" size="3"&gt;This results in a runtime error on the cast in the CastByType methods. That’s one more reason to be careful where you use this technique. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Still it’s cool to uncover new things in .NET 3.5.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&amp;nbsp;&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=1347606" 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/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>Detals of the VB 9.0 Compiler Bug</title><link>http://msmvps.com/blogs/kathleen/archive/2007/11/22/detals-of-the-vb-9-0-compiler-bug.aspx</link><pubDate>Thu, 22 Nov 2007 16:45:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1347571</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=1347571</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2007/11/22/detals-of-the-vb-9-0-compiler-bug.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;I’ve just posted a explanation of the &lt;/font&gt;&lt;a href="http://www.gendotnet.com/Home/TechnicalPapers/VisualBasic90CompilerBug/tabid/652/Default.aspx"&gt;&lt;font face="Calibri" size="3"&gt;VB 9.0 compiler bug at my website&lt;/font&gt;&lt;/a&gt;&lt;font face="Calibri" size="3"&gt;. I decided to post rather than blog because this represents my current best understanding of the problem. I want to keep a single copy up to date, which is not well suited to a blog. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;One note, I am using a C# project, but this bug can occur in VB only solutions. &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=1347571" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category></item><item><title>More on the VB 9.0 Compiler Bug</title><link>http://msmvps.com/blogs/kathleen/archive/2007/11/19/more-on-the-vb-9-0-compiler-bug.aspx</link><pubDate>Mon, 19 Nov 2007 23:20:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1337097</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=1337097</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2007/11/19/more-on-the-vb-9-0-compiler-bug.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;Let me give a little more information on the project which demonstrated the VB 9.0 compiler bug and think its best illustrated with a &lt;a class="" title="Link to November 19, 2007 Blog Entry" href="http://www.gendotnet.com/BlogDiagram20071119/tabid/651/Default.aspx"&gt;picture&lt;/a&gt;. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;In addition to having the accidently file reference from a stray assembly (Assembly1 in the picture) there is a relationship among four assemblies that drive the app (there are actually a few more, but these seem to be the relevant ones). To reuse and remove circular reference issues (with the other assemblies) there is a Common base assembly. There is also a GenericBase assembly which contains a set of generic based extensions to Rocky Lhotka’s CSLA. CSLA does not appear to be involved in the VB 9.0 compiler issue. The Common and GenericBase are reused for different application logic modules that happen to be written in C#. I wrote in C# because this is a huge assembly and offered unacceptable IDE performance prior to SP1 of VS 2005. I haven’t taken the time to go back and rewrite to VB, which I will do soon with the LINQ to XML generation approach. Finally, a WinForms application runs the application. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;I don’t think there is anything particularly unusual about the relationship between IBase, CBase(Of T As IBase), and CDerived. The syntax CBase(Of T As IBase) describes a generic class that restricts the type parameter to classes implementing IBase – providing the generic constraint that seems to be part of the problem. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;What is unusual is the inclusion of C# and VB in the same solution. If you’re doing that, I’ll be curious because I’m one of the few people that seem to encourage using the best tool for any task. Apparently the metadata reference that results contributes to the alignment of stars to cause the problem. I’m trying to find out how confident the team is that if you don’t cross languages you won’t encounter this problem. I’ll post more when I know more.&lt;/font&gt;&lt;/p&gt;&lt;font face="Calibri" size="3"&gt;&amp;nbsp;&lt;/font&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=1337097" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.01.33.70.97/Figure-1-B.jpg" length="55781" type="image/jpeg" /><category domain="http://msmvps.com/blogs/kathleen/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/kathleen/archive/tags/Visual+Basic/default.aspx">Visual Basic</category></item><item><title>How to Sidestep a Visual Basic Compiler Bug in RTM </title><link>http://msmvps.com/blogs/kathleen/archive/2007/11/19/how-to-sidestep-a-visual-basic-compiler-bug-in-rtm.aspx</link><pubDate>Mon, 19 Nov 2007 18:56:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1336183</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=1336183</wfw:commentRss><comments>http://msmvps.com/blogs/kathleen/archive/2007/11/19/how-to-sidestep-a-visual-basic-compiler-bug-in-rtm.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;A couple of weeks ago I ran into a very surprising bug in the Visual Basic compiler after upgrading a project from 2005 to 2008. To make a long debugging story shorter, I realized a line of code was not included in the IL output. This particular function call was missing regardless of how I rearranged the code in a Try block, etc. After confirming this with Reflector, I realized that there was a significant bug and worked as hard&amp;nbsp;to preserve the problem as to solve it. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;While I’m not happy that the VB compiler has such a serious bug, I am happy with the team’s response. I&amp;#39;m pleased in how they worked with my zipped project to confirm the problem and look beyond my immediate fix (a solution clean, worked out over IM with &lt;/font&gt;&lt;a href="http://msmvps.com/blogs/bill"&gt;&lt;font face="Calibri" size="3"&gt;Bill McCarthy&lt;/font&gt;&lt;/a&gt;&lt;font face="Calibri" size="3"&gt;). I&amp;#39;m also&amp;nbsp;happy that they quickly planned&amp;nbsp;a resolution, even if it couldn&amp;#39;t be ready for the RTM release. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;In case the magnitude of the problem isn’t clear yet, there is a scenario in which you cannot rely on fidelity between your source code and the IL that runs.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;At least two things have to happen for your project to be vulnerable to this issue – you have a constrained generic in an assembly and that assembly is referenced by both project and file references. It’s not clear to me why this confuses the Visual Basic compiler -&amp;nbsp;but it sometimes does and&amp;nbsp;the reason&amp;nbsp;is clear to the team. &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;The VB team plans a fix for SP1. Obviously that doesn’t help us today. You need to check your solutions for this mixed reference approach if you are using constrained generics in your common utility classes (which I’d encourage you to do because of the power of generics). There may be other conditions that have to also be in place for the bug that I don’t know about, but avoiding mixing file and project references is the easy way to break the offending cycle.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;The team is also working on communicating this problem and probably including a KB article that explains the problem. I expect they will also supply a tool to identify mixed references and set them all to project references for all the goodness that provides to Visual Basic. I’ll let them share their future plans in the &lt;/font&gt;&lt;a href="http://blogs.msdn.com/vbteam/"&gt;&lt;font face="Calibri" size="3"&gt;VB team blog&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;. Since RTM is out now, I want information on this out so you can protect your projects.&amp;nbsp;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;span style="mso-spacerun:yes;"&gt;I do not believe you should avoid the RTM release of VB 9.0 becuase of this bug.&amp;nbsp;I do think its important that you check your projects to ensure you don&amp;#39;t smack into this. And tell all your friends to do the same. &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 10pt;"&gt;&lt;font face="Calibri" size="3"&gt;I’ll have more links here as if there’s any new information and certainly to the KB article when its out.&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=1336183" 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/Visual+Basic/default.aspx">Visual Basic</category></item></channel></rss>