<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="http://code.msdn.microsoft.com/rss.xsl"?><rss version="2.0"><channel><title>Generic Class Factory</title><link>http://code.msdn.microsoft.com/aabs/Project/ProjectRss.aspx</link><description>A simple class factory using C&amp;#35; 3.0 that enables the easy insertion of mock objects during unit testing.</description><item><title>RELEASED: Generic Class Factory Snippet (Jan 29, 2008)</title><link>http://code.msdn.microsoft.com/aabs/Release/ProjectReleases.aspx?ReleaseId=80</link><description>For years I&amp;#8217;ve been using a design pattern I picked up back in my Java days to help me make legacy classes more testable with Mock objects. I&amp;#8217;ve always had a few doubts about it, but it&amp;#8217;s been useful so many times that I&amp;#8217;ve never bothered to change it. I always keep a handy code snippet for it on my dev machines and I can knock them out in seconds. I don&amp;#8217;t like it because I have to create a new class factory for every type that I want to control. This evening I decided it was about time that I brought it up to date with C&amp;#35; 3.0 and .NET 3.5.&lt;br /&gt;&lt;br /&gt;Usage for creating the default type&amp;#58;&lt;br /&gt;&lt;br /&gt;&amp;#123;&amp;#34;&amp;#91;&amp;#34;&amp;#125;Test&amp;#123;&amp;#34;&amp;#93;&amp;#34;&amp;#125;&lt;br /&gt;public void TestGenericClassFactory2&amp;#40;&amp;#41;&lt;br /&gt;&amp;#123;&lt;br /&gt;    GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.Dispenser &amp;#61; &amp;#40;args&amp;#41; &amp;#61;&amp;#62;&lt;br /&gt;        &amp;#40;IMyClass&amp;#41;Activator.CreateInstance&amp;#40;typeof&amp;#40;MyClass2&amp;#41;, args&amp;#41;&amp;#59;&lt;br /&gt;    IMyClass ad &amp;#61; GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.CreateInstance&amp;#40;1, 2, 3&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsNotNull&amp;#40;ad&amp;#41;&amp;#59;&lt;br /&gt;    Assert.AreEqual&amp;#40;ad.MyMethod&amp;#40;&amp;#41;, 6&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsTrue&amp;#40;ad is MyClass2&amp;#41;&amp;#59;&lt;br /&gt;&amp;#125;&lt;br /&gt;&lt;br /&gt;Usage for creating a special instance &amp;#40;such as a mock&amp;#41;&amp;#58;&lt;br /&gt;&amp;#123;&amp;#34;&amp;#91;&amp;#34;&amp;#125;Test&amp;#123;&amp;#34;&amp;#93;&amp;#34;&amp;#125;&lt;br /&gt;public void TestGenericClassFactoryBinding&amp;#40;&amp;#41;&lt;br /&gt;&amp;#123;&lt;br /&gt;    MyClass2 tmp &amp;#61; new MyClass2&amp;#40;2,3,4&amp;#41;&amp;#59;&lt;br /&gt;    GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.Dispenser &amp;#61; &amp;#40;args&amp;#41; &amp;#61;&amp;#62; tmp&amp;#59;&lt;br /&gt;    IMyClass ad &amp;#61; GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.CreateInstance&amp;#40;1, 2, 3&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsNotNull&amp;#40;ad&amp;#41;&amp;#59;&lt;br /&gt;    Assert.AreEqual&amp;#40;ad.MyMethod&amp;#40;&amp;#41;, 9&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsTrue&amp;#40;ad is MyClass2&amp;#41;&amp;#59;&lt;br /&gt;&amp;#125;&lt;br /&gt;&lt;br /&gt;Go to this blog post&amp;#58; &amp;#91;url&amp;#58;http&amp;#58;&amp;#47;&amp;#47;aabs.wordpress.com&amp;#47;2007&amp;#47;11&amp;#47;21&amp;#47;a-generic-class-factory-for-c-30&amp;#47;&amp;#93; for more information.&lt;br /&gt;</description><author></author><pubDate>Tue, 29 Jan 2008 07:57:19 GMT</pubDate><guid isPermaLink="false">RELEASED: Generic Class Factory Snippet (Jan 29, 2008) 20080129A</guid></item><item><title>UPDATED RELEASE: Generic Class Factory Snippet (Jan 29, 2008)</title><link>http://code.msdn.microsoft.com/aabs/Release/ProjectReleases.aspx?ReleaseId=80</link><description>For years I&amp;#8217;ve been using a design pattern I picked up back in my Java days to help me make legacy classes more testable with Mock objects. I&amp;#8217;ve always had a few doubts about it, but it&amp;#8217;s been useful so many times that I&amp;#8217;ve never bothered to change it. I always keep a handy code snippet for it on my dev machines and I can knock them out in seconds. I don&amp;#8217;t like it because I have to create a new class factory for every type that I want to control. This evening I decided it was about time that I brought it up to date with C&amp;#35; 3.0 and .NET 3.5.&lt;br /&gt;&lt;br /&gt;Usage for creating the default type&amp;#58;&lt;br /&gt;&lt;br /&gt;&amp;#123;&amp;#34;&amp;#91;&amp;#34;&amp;#125;Test&amp;#123;&amp;#34;&amp;#93;&amp;#34;&amp;#125;&lt;br /&gt;public void TestGenericClassFactory2&amp;#40;&amp;#41;&lt;br /&gt;&amp;#123;&lt;br /&gt;    GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.Dispenser &amp;#61; &amp;#40;args&amp;#41; &amp;#61;&amp;#62;&lt;br /&gt;        &amp;#40;IMyClass&amp;#41;Activator.CreateInstance&amp;#40;typeof&amp;#40;MyClass2&amp;#41;, args&amp;#41;&amp;#59;&lt;br /&gt;    IMyClass ad &amp;#61; GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.CreateInstance&amp;#40;1, 2, 3&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsNotNull&amp;#40;ad&amp;#41;&amp;#59;&lt;br /&gt;    Assert.AreEqual&amp;#40;ad.MyMethod&amp;#40;&amp;#41;, 6&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsTrue&amp;#40;ad is MyClass2&amp;#41;&amp;#59;&lt;br /&gt;&amp;#125;&lt;br /&gt;&lt;br /&gt;Usage for creating a special instance &amp;#40;such as a mock&amp;#41;&amp;#58;&lt;br /&gt;&amp;#123;&amp;#34;&amp;#91;&amp;#34;&amp;#125;Test&amp;#123;&amp;#34;&amp;#93;&amp;#34;&amp;#125;&lt;br /&gt;public void TestGenericClassFactoryBinding&amp;#40;&amp;#41;&lt;br /&gt;&amp;#123;&lt;br /&gt;    MyClass2 tmp &amp;#61; new MyClass2&amp;#40;2,3,4&amp;#41;&amp;#59;&lt;br /&gt;    GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.Dispenser &amp;#61; &amp;#40;args&amp;#41; &amp;#61;&amp;#62; tmp&amp;#59;&lt;br /&gt;    IMyClass ad &amp;#61; GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.CreateInstance&amp;#40;1, 2, 3&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsNotNull&amp;#40;ad&amp;#41;&amp;#59;&lt;br /&gt;    Assert.AreEqual&amp;#40;ad.MyMethod&amp;#40;&amp;#41;, 9&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsTrue&amp;#40;ad is MyClass2&amp;#41;&amp;#59;&lt;br /&gt;&amp;#125;&lt;br /&gt;&lt;br /&gt;Go to this blog post&amp;#58; &amp;#91;url&amp;#58;http&amp;#58;&amp;#47;&amp;#47;aabs.wordpress.com&amp;#47;2007&amp;#47;11&amp;#47;21&amp;#47;a-generic-class-factory-for-c-30&amp;#47;&amp;#93; for more information.&lt;br /&gt;</description><author></author><pubDate>Tue, 29 Jan 2008 07:57:19 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: Generic Class Factory Snippet (Jan 29, 2008) 20080129A</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/aabs/Wiki/View.aspx?title=Home&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Resource Page Description&lt;/b&gt;&lt;br /&gt;Snippets submitted by Andrew Matthews
&lt;br /&gt;
&lt;/div&gt;</description><author>aabs</author><pubDate>Tue, 29 Jan 2008 07:53:33 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080129A</guid></item><item><title>CREATED RELEASE: Generic Class Factory Snippet (Jan 29, 2008)</title><link>http://code.msdn.microsoft.com/aabs/Release/ProjectReleases.aspx?ReleaseId=80</link><description>For years I&amp;#8217;ve been using a design pattern I picked up back in my Java days to help me make legacy classes more testable with Mock objects. I&amp;#8217;ve always had a few doubts about it, but it&amp;#8217;s been useful so many times that I&amp;#8217;ve never bothered to change it. I always keep a handy code snippet for it on my dev machines and I can knock them out in seconds. I don&amp;#8217;t like it because I have to create a new class factory for every type that I want to control. This evening I decided it was about time that I brought it up to date with C&amp;#35; 3.0 and .NET 3.5.&lt;br /&gt;&lt;br /&gt;Usage for creating the default type&amp;#58;&lt;br /&gt;&lt;br /&gt;&amp;#91;Test&amp;#93;&lt;br /&gt;public void TestGenericClassFactory2&amp;#40;&amp;#41;&lt;br /&gt;&amp;#123;&lt;br /&gt;    GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.Dispenser &amp;#61; &amp;#40;args&amp;#41; &amp;#61;&amp;#62;&lt;br /&gt;        &amp;#40;IMyClass&amp;#41;Activator.CreateInstance&amp;#40;typeof&amp;#40;MyClass2&amp;#41;, args&amp;#41;&amp;#59;&lt;br /&gt;    IMyClass ad &amp;#61; GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.CreateInstance&amp;#40;1, 2, 3&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsNotNull&amp;#40;ad&amp;#41;&amp;#59;&lt;br /&gt;    Assert.AreEqual&amp;#40;ad.MyMethod&amp;#40;&amp;#41;, 6&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsTrue&amp;#40;ad is MyClass2&amp;#41;&amp;#59;&lt;br /&gt;&amp;#125;&lt;br /&gt;&lt;br /&gt;Usage for creating a special instance &amp;#40;such as a mock&amp;#41;&amp;#58;&lt;br /&gt;&amp;#91;Test&amp;#93;&lt;br /&gt;public void TestGenericClassFactoryBinding&amp;#40;&amp;#41;&lt;br /&gt;&amp;#123;&lt;br /&gt;    MyClass2 tmp &amp;#61; new MyClass2&amp;#40;2,3,4&amp;#41;&amp;#59;&lt;br /&gt;    GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.Dispenser &amp;#61; &amp;#40;args&amp;#41; &amp;#61;&amp;#62; tmp&amp;#59;&lt;br /&gt;    IMyClass ad &amp;#61; GenericClassFactory&amp;#60;IMyClass, MyClass&amp;#62;.CreateInstance&amp;#40;1, 2, 3&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsNotNull&amp;#40;ad&amp;#41;&amp;#59;&lt;br /&gt;    Assert.AreEqual&amp;#40;ad.MyMethod&amp;#40;&amp;#41;, 9&amp;#41;&amp;#59;&lt;br /&gt;    Assert.IsTrue&amp;#40;ad is MyClass2&amp;#41;&amp;#59;&lt;br /&gt;&amp;#125;&lt;br /&gt;&lt;br /&gt;Go to this blog post&amp;#58; &amp;#91;url&amp;#58;http&amp;#58;&amp;#47;&amp;#47;aabs.wordpress.com&amp;#47;2007&amp;#47;11&amp;#47;21&amp;#47;a-generic-class-factory-for-c-30&amp;#47;&amp;#93; for more information.&lt;br /&gt;</description><author></author><pubDate>Tue, 29 Jan 2008 07:52:37 GMT</pubDate><guid isPermaLink="false">CREATED RELEASE: Generic Class Factory Snippet (Jan 29, 2008) 20080129A</guid></item></channel></rss>