<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Anthony Trudeau</title>
        <link>http://geekswithblogs.net/tonyt/Default.aspx</link>
        <description />
        <language>en-US</language>
        <copyright>Anthony Trudeau</copyright>
        <managingEditor>agrt.home@hotmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Anthony Trudeau</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/tonyt/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Enterprise Library</title>
            <category>.NET</category>
            <link>http://geekswithblogs.net/tonyt/archive/2009/06/26/133079.aspx</link>
            <description>&lt;p&gt;The other day Lindsay Rutter with Microsoft did a &lt;a href="http://blogs.msdn.com/lindsay/archive/2009/06/25/msdn-webcast-enterprise-library-4-1.aspx#comments"&gt;webcast on the Enterprise Library&lt;/a&gt;.  I've used the exception handling block in a few projects, but my opinion had been that the library was bloated and was low on my priority list of technologies to investigate.&lt;/p&gt;
&lt;p&gt;The talk on dependency injection in the webcast changed my mind.  I immediately got a return on my investment as I wanted a more flexible method for tracing then what is offered from the Trace class in the System.Diagnostics namespace.  And most importantly I didn't want any unnecessary dependencies in my library.  Basically, my library wants the ability to log, but doesn't want any responsibility for it.  Here's what I did:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Added a reference to the Microsoft.Practices.Unity library.  You'll need the Microsoft.Practices.ObjectBuilder2 library referenced wherever you create the unity container and inject the dependency.  My library doesn't care about that.  All it cares about is that whatever creates the key objects creates the dependencies.&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Define the interface for classes to perform the work.  I created the ILoggingHandler with methods such as LogError, LogWarning, and LogInformation.&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Add a using statement for Microsoft.Practices.Unity to the code files containing your classes that you will be injecting.&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Add the following code to the classes that I want to log.  There are undoubtedly other ways to approach this, but this is the most simple.  At first I didn't think it was very elegant to add a property to my class, but these are base classes providing a service to subclasses, so I warmed up to the idea.&lt;br /&gt;
    &lt;br /&gt;
    &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs22         [\cf3 Dependency\cf0 ]\par ??        \cf4 public\cf0  \cf3 ILoggingHandler\cf0  LogHandler \{ \cf4 get\cf0 ; \cf4 set\cf0 ; \}}
--&gt;
    &lt;div style="FONT-FAMILY: Consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 11pt"&gt;
    &lt;p style="MARGIN: 0px"&gt;[&lt;span style="COLOR: #2b91af"&gt;Dependency&lt;/span&gt;]&lt;/p&gt;
    &lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ILoggingHandler&lt;/span&gt; LogHandler { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt; Use the property within your code where necessary as in the following code.&lt;br /&gt;
    &lt;br /&gt;
    &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red163\green21\blue21;}??\fs22 LogHandler.LogInformation(\cf3 "Enter trace information here"\cf0 );}
--&gt;
    &lt;div style="FONT-FAMILY: Consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 11pt"&gt;
    &lt;p style="MARGIN: 0px"&gt;LogHandler.LogInformation(&lt;span style="COLOR: #a31515"&gt;"Enter trace information here"&lt;/span&gt;);&lt;/p&gt;
    &lt;/div&gt;
    &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt; It's perfect for what I needed and is extremely simple to implement.  When it comes to creating the logging service class I can create it and inject it from the code that hosts these classes using the following code (where DefaultLoggingHandler is my implementation of ILoggingHandler).&lt;br /&gt;
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;}??\fs22 container.RegisterType&amp;lt;ILogHandler, ConcreteLogger&amp;gt;(\cf3 new\cf0  ContainerControlledLifetimeManager());\par ??                Application.Run(container.Resolve&amp;lt;Form1&amp;gt;());}
--&gt;
&lt;div style="FONT-FAMILY: Consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 11pt"&gt;
&lt;div style="FONT-FAMILY: Consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 11pt"&gt;
&lt;p style="MARGIN: 0px"&gt;IUnityContainer container = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; UnityContainer();&lt;/p&gt;
&lt;/div&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;!--EndFragment--&gt;container.RegisterType&amp;lt;ILoggingHandler, DefaultLoggingHandler&amp;gt;(&lt;span style="COLOR: blue"&gt;new&lt;/span&gt; ContainerControlledLifetimeManager());&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;MySubClass obj = container.Resolve&amp;lt;MySubClass&amp;gt;();&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;
The optional parameter I specified in the call to RegisterType allows the object to be created as a Singleton.  That means that every MySubClass object I create will use the same DefaultLoggingHandler.&lt;/p&gt;
&lt;p&gt;I suggest that anyone who has discounted the Enterprise Library in the past take another look.  I first used the Enterprise Library in one of it's first interations.  It's grown and matured and can make some common, time consuming development activities go away.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133079"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133079" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/tonyt/aggbug/133079.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Anthony Trudeau</dc:creator>
            <guid>http://geekswithblogs.net/tonyt/archive/2009/06/26/133079.aspx</guid>
            <pubDate>Fri, 26 Jun 2009 17:49:47 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/tonyt/comments/133079.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/tonyt/archive/2009/06/26/133079.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/tonyt/comments/commentRss/133079.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/tonyt/services/trackbacks/133079.aspx</trackback:ping>
        </item>
        <item>
            <title>SCSF Guidance Recipes Not Available</title>
            <category>.NET</category>
            <link>http://geekswithblogs.net/tonyt/archive/2009/04/23/131411.aspx</link>
            <description>&lt;p&gt;I ran into a problem with a Smart Client Software Factory (SCSF) solution that I'm working on.  I created my modules and then attempted to create my views within those modules.  I used the "Add View (with presenter)" recipe; however, the resulting dialog would not let me select my module projects.&lt;/p&gt;
&lt;p&gt;The requirements for running the recipe are that you need to reference the main composite application libraries namely Microsoft.Practices.CompositeUI and Microsoft.Practices.ObjectBuilder and you need a reference to your Infrastructure.Interface project.  All of these requirements were in place.&lt;/p&gt;
&lt;p&gt;I came upon a comment buried on page that laid out a very complex solution that involved rebuilding the guidance package from source code.  The comment laid out an alternate way to work around the problem; although in of itself it isn't a great solution.&lt;/p&gt;
&lt;p&gt;Here are the steps:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Open the Properties for your Infrastructure.Interface project&lt;/li&gt;
    &lt;li&gt;Remove the solution name from the assembly name (the assembly name should then be Infrastructure.Interface)&lt;/li&gt;
    &lt;li&gt;Save and rebuild the solution&lt;/li&gt;
    &lt;li&gt;Run all of the recipes you need&lt;/li&gt;
    &lt;li&gt;Restore the solution name&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Like I said this isn't a great solution, but I don't have time to mess with rebuilding the guidance package and everything else that might entail.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131411"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131411" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/tonyt/aggbug/131411.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Anthony Trudeau</dc:creator>
            <guid>http://geekswithblogs.net/tonyt/archive/2009/04/23/131411.aspx</guid>
            <pubDate>Thu, 23 Apr 2009 22:26:09 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/tonyt/comments/131411.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/tonyt/archive/2009/04/23/131411.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/tonyt/comments/commentRss/131411.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/tonyt/services/trackbacks/131411.aspx</trackback:ping>
        </item>
        <item>
            <title>Using an UltraExplorerBarGroup as a UIExtensionSite</title>
            <category>Infragistics</category>
            <category>.NET</category>
            <link>http://geekswithblogs.net/tonyt/archive/2009/04/14/130967.aspx</link>
            <description>&lt;p&gt;The Infragistics NetAdvantage control suite provides good support for the composite application block (part of the smart client software factory).  However, I ran into the difficulty today when I wanted to extend an existing group in an UltraExplorerBar instance.&lt;/p&gt;
&lt;p&gt;I'm using an UltraExplorerBarWorkspace in my ShellLayoutView.  At the start, it contains only one group with the text "Properties" and the key "PropertyGroup".  I have the need for modules to add their own groups and to add items to the "PropertyGroup".  The former is straightforward and just requires you to create a group in the module and add it dynamically to the extension site.  The latter, however, isn't clear at all.&lt;/p&gt;
&lt;p&gt;I started out by defining my extension site to use the UltraExplorerBarGroup with the key "PropertyGroup".  The site was registered in my view's presenter class and then referenced in the module's controller class using the following code (simplified for brevity):&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;div style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;UIExtensionSite&lt;/span&gt; propertyGroup = &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   WorkItem.UIExtensionSites[&lt;span style="COLOR: #2b91af"&gt;UIExtensionSiteNames&lt;/span&gt;.PropertyGroup];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;propertyGroup.Add(&lt;span style="COLOR: #2b91af"&gt;ViewElementFactory&lt;/span&gt;.CreateCoilPropertiesItem());&lt;/p&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In this code, CreateCoilPropertiesItem returns a new UltraExplorerBarItem.  Unfortunately, the code doesn't work.  You get an exception of type ModuleLoadException with the text:&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;Failed to load module from assembly ...  Error was: UI element must be a Infragistics.Win.UltraWinExplorerBar.UltraExplorerBarGroup.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The UltraExplorerBarGroup can contain other UltraExplorerBarGroup instances as well as UltraExplorerBarItem instances.  Therefore, I tried it again but this time when I registered my UI extension site I registered the Items collection of the UltraExplorerBarGroup like the following:&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;div style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;font color="#339966"&gt;// property within the ShellLayoutView&lt;/font&gt;&lt;br /&gt;
internal&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;UltraExplorerBarItemsCollection&lt;/span&gt; PropertyGroup&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;       &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _leftWorkspace.Groups[&lt;span style="COLOR: #a31515"&gt;"PropertyGroup"&lt;/span&gt;].Items;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;font color="#339966"&gt;// code within the view's presenter&lt;/font&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;WorkItem.UIExtensionSites.RegisterSite(&lt;span style="COLOR: #2b91af"&gt;UIExtensionSiteNames&lt;/span&gt;.PropertyGroup, View.PropertyGroup);&lt;/p&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;That did the trick.  And although it wasn't clear it wasn't hard to figure out.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130967"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130967" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/tonyt/aggbug/130967.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Anthony Trudeau</dc:creator>
            <guid>http://geekswithblogs.net/tonyt/archive/2009/04/14/130967.aspx</guid>
            <pubDate>Tue, 14 Apr 2009 22:33:22 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/tonyt/comments/130967.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/tonyt/archive/2009/04/14/130967.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/tonyt/comments/commentRss/130967.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/tonyt/services/trackbacks/130967.aspx</trackback:ping>
        </item>
        <item>
            <title>Simple explanation for co-variance and contra-variance</title>
            <category>.NET</category>
            <link>http://geekswithblogs.net/tonyt/archive/2009/04/13/130938.aspx</link>
            <description>&lt;p&gt;Co-variance and contra-variance have always been two terms for me that made me pause.  Neither are hard to understand and we often use what they mean instinctively in object-oriented programming.  However, before today if you were to ask me what they were I would have to give you an example.  For some reason, a clear, concise definition escaped me.&lt;/p&gt;
&lt;p&gt;Then today I read a blog post on &lt;a href="http://software.intel.com/en-us/blogs/2009/03/30/the-c-programming-language-version-40/"&gt;C# v4.0 on the Intel website&lt;/a&gt; that summed it up in one of those "ah ha" and "duh" moments.&lt;/p&gt;
&lt;p&gt;Co-variance is when you treat something more derived as something less derived&lt;br /&gt;
Contra-variance is when you treat something less derived as something more derived&lt;/p&gt;
&lt;p&gt;And the examples (not designed to model anything real) are easy:&lt;/p&gt;
&lt;p&gt;// co-variance&lt;br /&gt;
private void DoSomething(object[] objects) { ... }&lt;/p&gt;
&lt;p&gt;string[] myStrings = new string[] { "a", "b", ... };&lt;br /&gt;
DoSomething(myStrings);&lt;/p&gt;
&lt;p&gt;// contra-variance&lt;br /&gt;
private void DoSomething(MyConcreteObjectA a) { ... }&lt;/p&gt;
&lt;p&gt;private void DoSomething(MyConcreteObjectB b) { ... }&lt;/p&gt;
&lt;p&gt;private MyObjectBase CreateObject() { ... }&lt;/p&gt;
&lt;p&gt;MyObjectBase newObject = CreateObject();&lt;br /&gt;
DoSomething(newObject);&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130938"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130938" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/tonyt/aggbug/130938.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Anthony Trudeau</dc:creator>
            <guid>http://geekswithblogs.net/tonyt/archive/2009/04/13/130938.aspx</guid>
            <pubDate>Mon, 13 Apr 2009 19:32:49 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/tonyt/comments/130938.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/tonyt/archive/2009/04/13/130938.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/tonyt/comments/commentRss/130938.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/tonyt/services/trackbacks/130938.aspx</trackback:ping>
        </item>
        <item>
            <title>Learning Ruby: First Thoughts</title>
            <category>Ruby</category>
            <link>http://geekswithblogs.net/tonyt/archive/2009/03/20/130273.aspx</link>
            <description>&lt;p&gt;I posted a few weeks ago about not being able to find time to learn a new language.  Well this week I got a beginners book on Ruby for my birthday; and I've decided to make a concerted effort to find the time -- even if it's just a bit of time.&lt;/p&gt;
&lt;p&gt;Ruby is an interesting language.  It bills itself as being expressive and so far I have to agree.  Although there are some notable exceptions.  For example, I don't think it's very clear that the following line of Ruby code changes the elements in the array for each element.&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;[1, 2, 3, 4].collect { |element| element * 2 }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;On the other hand I really like how the regular expressions are integrated within the string handling -- C# and other .NET languages use the RegEx class.  For example, in Ruby I can replace a call to a static Match method on the RegEx class with the following (it's definitely more expressive).&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;puts "String has vowels" if mystring.match(/[aeiou]/)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Typing is probably my biggest concern.  I'm used to strongly-typed languages.  When I was programming Visual Basic I always loathed the Variant, and for that matter I'm a little squeemish on using the Object type (I heart you Generics).  Ruby is not strongly-typed, but it seems to be dynamically typed rather than weakly typed (what I've read so far hasn't elaborated on it).  The following two code examples illustrate why Ruby isn't weakly typed.&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;'VB for Applications example&lt;br /&gt;
Dim x(2) As Variant&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;x(0) = 1&lt;br /&gt;
x(1) = 2&lt;br /&gt;
x(2) = 3&lt;br /&gt;
&lt;br /&gt;
If x(2) = 3 Then Debug.Print "x(2) = 3"&lt;br /&gt;
If x(2) = "3" Then Debug.Print "x(2) = '3'"&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;The example in VB for Applications will display both messages, because the integer in the array is coerced into a string for the comparison.&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;#Ruby example&lt;br /&gt;
x = [1, 2, 3]&lt;br /&gt;
&lt;br /&gt;
puts x.include?(3)&lt;br /&gt;
puts x.include?("3")&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This example will display true and false for each line respectively.  There doesn't seem to be any evil type coercion.&lt;/p&gt;
&lt;p&gt;At the fear of looking like a complainer I have to say my first impression of Ruby is with the tools they provide.  Specifically, fxri which is first day program simple looking.  I like that you get some documentation there (since there is nothing like Intellisense anywhere), but why does it have to load every single topic into the pane; and why does the pane indicate that there are 13,438 of 13,437 entries...  &lt;/p&gt;
&lt;p&gt;Overall, I'm enjoying the experience.  I'm not sold on the language and at this point I'm not sure what it brings to the table for me as a C# developer; but I've only been looking at it for a few days so the jury is out.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130273"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130273" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/tonyt/aggbug/130273.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Anthony Trudeau</dc:creator>
            <guid>http://geekswithblogs.net/tonyt/archive/2009/03/20/130273.aspx</guid>
            <pubDate>Fri, 20 Mar 2009 21:01:57 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/tonyt/comments/130273.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/tonyt/archive/2009/03/20/130273.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/tonyt/comments/commentRss/130273.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/tonyt/services/trackbacks/130273.aspx</trackback:ping>
        </item>
        <item>
            <title>How do you stay fresh?</title>
            <link>http://geekswithblogs.net/tonyt/archive/2009/03/10/129979.aspx</link>
            <description>&lt;p&gt;This isn't a post on personal hygiene, but of skills.  My responsibilities at work keep me so busy that I barely have time to read an article let alone learn a new language or technology.  I have a sizable library of books and I read through them whenever I get a chance, but often don't have the time to really go indepth and practice on the technology.  I suppose it's better than nothing.&lt;/p&gt;
&lt;p&gt;Now if I were a bachelor and didn't have my daughter (wouldn't trade her for anything even programming) it wouldn't be a problem.  My off-roading hobby is a weekend activity when I get a chance to do it, so on most evenings I would have time to cozy up with a book on the latest and greatest technology, read some articles or blog posts, and possibly even learn a new language.  That isn't an option though.  So I'm curious, do any of y'all have tips for keeping your skills fresh?  &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129979"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129979" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/tonyt/aggbug/129979.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Anthony Trudeau</dc:creator>
            <guid>http://geekswithblogs.net/tonyt/archive/2009/03/10/129979.aspx</guid>
            <pubDate>Tue, 10 Mar 2009 15:25:12 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/tonyt/comments/129979.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/tonyt/archive/2009/03/10/129979.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/tonyt/comments/commentRss/129979.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/tonyt/services/trackbacks/129979.aspx</trackback:ping>
        </item>
        <item>
            <title>Simple Caching</title>
            <category>.NET</category>
            <link>http://geekswithblogs.net/tonyt/archive/2009/02/24/129642.aspx</link>
            <description>&lt;p&gt;In a current project I had a need for a lightweight caching mechanism.  My needs were driven by a desire to minimize file access.  The file in question would likely not be too long; however, I couldn't guarantee that.  Therefore, a caching framework such as provided by the Enterprise Library was just too much.  This post talks about what I put together.  The following are the only imports necessary.&lt;/p&gt;
&lt;div style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;My requirements are simple enough.  I want to be able to add an object to a cache based on a string name.  I want to be able to retrieve that same object, and I want to be able to determine (without raising an exception) if the cache contains an object.  And I want to be able to clear the cache.  I will clear the cache if I determine that my file has changed -- thus likely invalidating data within the cache.  Of course I want it strongly typed and to support any type of object (for future use)  and finally it needs to be thread safe.  Here's the pseudo-code interface:&lt;/p&gt;
&lt;p&gt;void Add(string key, T newObject)&lt;br /&gt;
T GetObject(string key)&lt;br /&gt;
void Clear()&lt;br /&gt;
bool IsCached(string key)&lt;/p&gt;
&lt;p&gt;All of these requirements are simple to implement.  But, I decided that I would add support for one more thing -- ICloneable.  The support wouldn't be an interface implementation, but rather supporting the caching of objects that implement the interface.  This can be important, because the objects I deal with are mutable and I don't want external code to corrupt my object state.&lt;/p&gt;
&lt;p&gt;Here's the completed class that does everything I need.&lt;/p&gt;
&lt;div style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: gray"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ObjectCache&lt;/span&gt;&amp;lt;T&amp;gt;
&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;, T&amp;gt; _cache = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;, T&amp;gt;();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; _syncObject = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: gray"&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; ObjectCache()
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Add(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; key, T newObject)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(key))&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"key"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (newObject == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"newObject"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: green"&gt;/* create a clone copy for the cache if the object implements&lt;br /&gt;
         * ICloneable; this provides an&lt;/span&gt;&lt;span style="COLOR: green"&gt; immutable collection of cached objects */&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        T cacheObject = (newObject &lt;span style="COLOR: blue"&gt;is&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ICloneable&lt;/span&gt; &lt;br /&gt;
                        ? (T)((&lt;span style="COLOR: #2b91af"&gt;ICloneable&lt;/span&gt;)newObject).Clone() : newObject);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;lock&lt;/span&gt; (_syncObject)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            _cache.Add(key, cacheObject);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: gray"&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; T GetObject(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; key)
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        T cacheObject;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;lock&lt;/span&gt; (_syncObject)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            cacheObject = _cache[key];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: green"&gt;/* return a copy of the cached object to enforce the&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: green"&gt;         * immutable collection */&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; (cacheObject &lt;span style="COLOR: blue"&gt;is&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ICloneable&lt;/span&gt; &lt;br /&gt;
               ? (T)((&lt;span style="COLOR: #2b91af"&gt;ICloneable&lt;/span&gt;)cacheObject).Clone() : cacheObject);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: gray"&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Clear()
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;lock&lt;/span&gt; (_syncObject)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;           _cache.Clear();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: gray"&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; IsCached(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; key)
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;lock&lt;/span&gt; (_syncObject)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _cache.ContainsKey(key);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;}&lt;!--EndFragment--&gt;&lt;!--EndFragment--&gt;&lt;/p&gt;
&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129642"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129642" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/tonyt/aggbug/129642.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Anthony Trudeau</dc:creator>
            <guid>http://geekswithblogs.net/tonyt/archive/2009/02/24/129642.aspx</guid>
            <pubDate>Tue, 24 Feb 2009 17:08:14 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/tonyt/comments/129642.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/tonyt/archive/2009/02/24/129642.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/tonyt/comments/commentRss/129642.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/tonyt/services/trackbacks/129642.aspx</trackback:ping>
        </item>
        <item>
            <title>Unit testing for serialization</title>
            <category>.NET</category>
            <link>http://geekswithblogs.net/tonyt/archive/2009/01/04/128352.aspx</link>
            <description>&lt;p&gt;I'm created a simple utility class for unit testing serialization for my first post of the year.  I originally created the class to test data contract serialization, but I extended it for IFormatter based serializers for another class I needed to test.  I hope it proves useful.&lt;/p&gt;
&lt;p&gt;You'll need the following using statements:&lt;/p&gt;
&lt;div style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.IO;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Runtime.Serialization;&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;p&gt;The following utility class will help you with unit testing serialization for your data contracts and serialization using a standard IFormatter:&lt;/p&gt;
&lt;div style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SerializationHelper&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; SerializeDataContract&amp;lt;T&amp;gt;(T testObject) &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; T: &lt;span style="COLOR: blue"&gt;class&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; fileName = &lt;span style="COLOR: #2b91af"&gt;Path&lt;/span&gt;.GetTempFileName();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;FileStream&lt;/span&gt; stream = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileStream&lt;/span&gt;(fileName, &lt;span style="COLOR: #2b91af"&gt;FileMode&lt;/span&gt;.OpenOrCreate))&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: #2b91af"&gt;DataContractSerializer&lt;/span&gt; serializer = &lt;br /&gt;
                &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DataContractSerializer&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(T));&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            serializer.WriteObject(stream, testObject);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; fileName;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; SerializeObject&amp;lt;TObject, TFormatter&amp;gt;(TObject testObject)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; TObject : &lt;span style="COLOR: blue"&gt;class&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; TFormatter : &lt;span style="COLOR: #2b91af"&gt;IFormatter&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; fileName = &lt;span style="COLOR: #2b91af"&gt;Path&lt;/span&gt;.GetTempFileName();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;FileStream&lt;/span&gt; stream = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileStream&lt;/span&gt;(fileName, &lt;span style="COLOR: #2b91af"&gt;FileMode&lt;/span&gt;.OpenOrCreate))&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: #2b91af"&gt;IFormatter&lt;/span&gt; serializer = &lt;span style="COLOR: #2b91af"&gt;Activator&lt;/span&gt;.CreateInstance&amp;lt;TFormatter&amp;gt;();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            serializer.Serialize(stream, testObject);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; fileName;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; T DeserializeDataContract&amp;lt;T&amp;gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; fileName) &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; T : &lt;span style="COLOR: blue"&gt;class&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;FileStream&lt;/span&gt; stream = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileStream&lt;/span&gt;(fileName, &lt;span style="COLOR: #2b91af"&gt;FileMode&lt;/span&gt;.Open))&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: #2b91af"&gt;DataContractSerializer&lt;/span&gt; serializer = &lt;br /&gt;
                &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DataContractSerializer&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(T));&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; (serializer.ReadObject(stream) &lt;span style="COLOR: blue"&gt;as&lt;/span&gt; T);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; TObject DeserializeObject&amp;lt;TObject, TFormatter&amp;gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; fileName)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; TObject : &lt;span style="COLOR: blue"&gt;class&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; TFormatter : &lt;span style="COLOR: #2b91af"&gt;IFormatter&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;FileStream&lt;/span&gt; stream = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileStream&lt;/span&gt;(fileName, &lt;span style="COLOR: #2b91af"&gt;FileMode&lt;/span&gt;.Open))&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: #2b91af"&gt;IFormatter&lt;/span&gt; serializer = &lt;span style="COLOR: #2b91af"&gt;Activator&lt;/span&gt;.CreateInstance&amp;lt;TFormatter&amp;gt;();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; (serializer.Deserialize(stream) &lt;span style="COLOR: blue"&gt;as&lt;/span&gt; TObject);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;p&gt;The following is a sample of how you can use the utility class to test a data contract based class (source and target are both objects of the same data contract type):&lt;/p&gt;
&lt;div style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; serializedFile = &lt;span style="COLOR: #2b91af"&gt;SerializationHelper&lt;/span&gt;.SerializeDataContract(source);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;target = &lt;span style="COLOR: #2b91af"&gt;SerializationHelper&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;    &lt;/span&gt;.DeserializeDataContract&amp;lt;&lt;span style="COLOR: #2b91af"&gt;WorkflowRequest&lt;/span&gt;&amp;gt;(serializedFile);&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=128352"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=128352" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/tonyt/aggbug/128352.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Anthony Trudeau</dc:creator>
            <guid>http://geekswithblogs.net/tonyt/archive/2009/01/04/128352.aspx</guid>
            <pubDate>Sun, 04 Jan 2009 22:54:33 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/tonyt/comments/128352.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/tonyt/archive/2009/01/04/128352.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/tonyt/comments/commentRss/128352.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/tonyt/services/trackbacks/128352.aspx</trackback:ping>
        </item>
    </channel>
</rss>