<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Developing For .NET &#187; .NET 3.5</title>
	<atom:link href="http://www.developingfor.net/category/net-35/feed" rel="self" type="application/rss+xml" />
	<link>http://www.developingfor.net</link>
	<description>Real World .NET Methods, Tricks, and Examples</description>
	<lastBuildDate>Mon, 01 Mar 2010 16:32:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>My first real WPF and Blend 2 application</title>
		<link>http://www.developingfor.net/c-30/my-first-real-wpf-and-blend-2-application.html</link>
		<comments>http://www.developingfor.net/c-30/my-first-real-wpf-and-blend-2-application.html#comments</comments>
		<pubDate>Tue, 21 Oct 2008 21:51:17 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Expression]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=168</guid>
		<description><![CDATA[I&#8217;ve been familiar with WPF since December 2006 and the release of C# 3.0, and I&#8217;ve had Expression Suite installed for almost a year.  While I&#8217;ve toyed with it here and there, I have never devoted the time and effort necessary to really begin to become proficient.
However, since last week&#8217;s Silverlight 2.0 release, I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been familiar with WPF since December 2006 and the release of C# 3.0, and I&#8217;ve had Expression Suite installed for almost a year.  While I&#8217;ve toyed with it here and there, I have never devoted the time and effort necessary to really begin to become proficient.</p>
<p>However, since last week&#8217;s Silverlight 2.0 release, I have been burying myself again in learning new technologies.  I finally decided to take the plunge, so I <a title="Silverlight Get Started page" href="http://silverlight.net/GetStarted/" target="_blank">installed Silverlight 2.0</a>, the Visual Studio updates, and upgraded to Expression Suite 2 SP1.  I spent a couple of days going through <a title="ScottGu Silverlight tutorial" href="http://weblogs.asp.net/scottgu/pages/silverlight-2-end-to-end-tutorial-building-a-digg-search-client.aspx" target="_blank">ScottGu&#8217;s tutorials</a> and some others on <a title="Silverlight Homepage" href="http://silverlight.net/" target="_blank">Silverlight.net</a>.  I followed along and built the samples, some in Visual Studio and some in Blend.</p>
<p>Most of these have been around for a while, so I&#8217;m not claiming any kind of leading edge stuff here.  What I wanted to do was to share some of the insights I&#8217;ve had in attempting this project.</p>
<p><strong>What&#8217;s the big deal</strong></p>
<p>XAML marks a sea change in how user interfaces are developed.  The end result of XAML is still .NET objects, and as such they can be created and managed programmaticaly, but the ability to simply describe what you want is very attractive.  For a long time, I did not like XAML itself, and one of my reasons for putting off learning WPF was that I wanted to wait until something like Blend made all XAML interaction obsolete.  After diving in for a few days, I no longer feel that way, but I&#8217;ll share more about that later.</p>
<p>What really makes all this so attractive is the ability to do basically whatever I can imagine for an interface.  More importantly, I can do it without a ton of hand coded control drawing, something I never liked doing in the first place.  The behavior of a control truly is separate from its presentation, and the presentation can be altered or replaced in any number of ways.  In other words, you can achieve some pretty cool effects with a reasonably small effort.</p>
<p><strong>Visual Studio or Blend?</strong></p>
<p>I&#8217;ve been having an ongoing discussion with a friend of mine at RVNUG about the usefulness of writing WPF applications within Visual Studio.  Having seen some demos and had some training on Blend, I was staunchly in the Blend corner on this one.  While you can drag and drop controls in Visual Studio, it takes a lot of hands on XAML coding to get anything more than a rudimentary window up and running.  As I mentioned previously, after seeing some XAML presentations I really wanted to avoid that as much as possible, which is what makes Blend so intriguing.</p>
<p>But, having gone through ScottGu&#8217;s Silverlight tutorial and building an application in Visual Studio, I have a better appreciation for it now.  One thing I do like about using Visual Studio is that it is keyboard centric.  As a classic Midrange developer I have always shied away from using the mouse as much as possible, so it appeals to my keyboard-philia.  And of course, Intellisense is still <em>the</em> killer feature and makes it much more palatable.  Also, as a seasoned and grizzled web developer who still likes the occasional dip into VI and Notepad, it only took a little time with XAML to feel comfortable with what was going on.  Anyone familiar with XHTML and CSS should find XAML completely doable.  It is, of course, a lot more complex, with numerous options and quirks, but it is still familiar territory.</p>
<p>Now, all that being said, I still prefer Blend 5 to 1 over Visual Studio for Visual XAML development.  I have only run into a few things that I couldn&#8217;t accomplish easily through Blend, and I&#8217;m new enough to it that I still chalk it up to just not knowing the tool well enough.  Applying and developing styles is still one of these areas: I so far have not figured out how to do them in Blend, so I revert to XAML editing.</p>
<p>Which brings me to my question of the day: &#8220;Should I use Visual Studio or Blend?&#8221;  The answer is a resounding &#8220;both!&#8221;  OK, I&#8217;m sure you saw that one coming, but let me explain my position.  If you are a developer, there is no question that you are going to use Visual Studio.  After all, it is our bread and butter, and all the real code will still be developed in our beloved IDE.  But designing serious WPF solutions in Visual Studio would be far too painful, even with great Intellisense support.  There are simply too many options to have to code them by hand.</p>
<p>It reminds me of my first Windows application: a Java Swing application that I<em> wrote in Wordpad. </em>Believe me, the pain of that experience made me instantly recognize the value of Visual Studio and is largely responsible for my shift to Microsoft technologies. On the same order, as soon as I saw Blend I knew that this was the tool I needed to design good WPF applications.  So, for layout and Visual Tree management, use Blend.  When you find a problem that you think you must solve using XAML editing, switch over to Visual Studio and take advantage of Intellisense, which Blend does not have.</p>
<p><strong>Quirks</strong></p>
<p>A couple of things so far have jumped out at me.  While Blend and Visual Studio do a pretty good job of keeping each other in synch, there are a couple of irregularities.</p>
<p>The first real problem I had was in adding existing projects to my solution in Visual Studio.  I started my solution in Visual Studio and then opened it up in Blend to work on the design.  Later in the same session, I went back to Visual Studio and added several projects.  Now that I had some CLR objects to work with, I wanted to try Data Binding, so I followed one of the online tutorials but no joy.  No matter what I did, I could not get Blend to find the objects.  Every time I tried, I received a slew of &#8220;file could not be located&#8221; errors.  Finally, I restarted Blend and when I opened my solution, there the missing objects were.</p>
<p>Second, there have been several times when I&#8217;m not sure that I am being properly prompted to reload.  I could be imagining it, but I feel pretty strongly that I have made changes in one without being prompted by the other to reload them.  Perhaps this is just a matter of timing Saves.</p>
<p><strong>Conclusion</strong></p>
<p>Well, I don&#8217;t really have any as of yet.  I do think that a lot of developers are going to struggle against the designer learning curve, yours truly included.  But I think in the long run we will be much better off.  So far, I am pleased with my efforts.  I like the combination of resources the two applications provide me, and I amd getting more comfortable in deciding which to use for certain scenarios.</p>
<p>I&#8217;m not quite ready for a tutorial series, but I will try to share some of my learning with you all as I go.  In the meantime, give it a try yourself and let us know what you think.  Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/c-30/my-first-real-wpf-and-blend-2-application.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Live Blogging &#8211; MSDN Mid-Atlantic Roadshow</title>
		<link>http://www.developingfor.net/net/live-blogging-msdn-mid-atlantic-roadshow.html</link>
		<comments>http://www.developingfor.net/net/live-blogging-msdn-mid-atlantic-roadshow.html#comments</comments>
		<pubDate>Tue, 30 Sep 2008 15:56:18 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=144</guid>
		<description><![CDATA[Today I am in Roanoke, VA at the MSDN Mid-Atlantic Roadshow.  This Microsoft event highlights Web development and .NET 3.5.
Web Development Basics &#8211; 9am

Presented by Andrew Duthie, Microsoft Technology Evangelist.  Andrew presents a nice history and overview of web development, from HTML/XHTML, Classic ASP, and up to ASP.NET.  It definitely confirms my [...]]]></description>
			<content:encoded><![CDATA[<p>Today I am in Roanoke, VA at the MSDN Mid-Atlantic Roadshow.  This Microsoft event highlights Web development and .NET 3.5.</p>
<p><strong>Web Development Basics &#8211; 9am<br />
</strong></p>
<p>Presented by <a title="Andrew Duthie" href="http://blogs.msdn.com/gduthie" target="_blank">Andrew Duthie</a>, Microsoft Technology Evangelist.  Andrew presents a nice history and overview of web development, from HTML/XHTML, Classic ASP, and up to ASP.NET.  It definitely confirms my opinion that I am glad I never was a Classic ASP developer!</p>
<p>He discussed Postback and ViewState, (my least favorite features of ASP.NET and hence my appreciation of ASP.NET MVC.)  I know this is not a popular ASP.NET view point, but it makes it difficult for traditional web developers like myself to step into an ASP.NET role.  One thing he mentioned was that you can disable ViewState for particular controls, for performance reasons.  You would only do this if the element was for display only.</p>
<p>He also discussed one of my favorite features, Master Pages.  I have long used this same concept in PHP development and I immediately recognized it in ASP.NET.</p>
<p>Note to self: learn about Membership Profiles.  I&#8217;ve been developing my own because I am connecting to a non-standard data source (IBM iSeries DB2).  Andrew said you can write your own custom backend but still use the built in Profile features.</p>
<p>DataBinding Demo: he showed a typical GridView Control bound to a SqlDataSource.  &#8220;Declarative Data Binding&#8221; &#8211; there is no executable code that drives the GridView, it is all expressed in the ASPX.  It is fast and easy to develop, but you still have the option to develop your own binding for more control.</p>
<p>Web Services: ASMX and WCF Services both supported.  ASMX is simpler, and hosted on IIS, but harder to make cross platform capable.  WCF is more complex to configure and can be hosted by any .NET process. ADO.NET Data Services uses WCF.  WCF can be used to communicate between servers and applications.  &#8220;ABC&#8221;s of WCF: Address, Binding, Contract.  I think it&#8217;s time I learned about WCF&#8230;</p>
<p><strong>What&#8217;s New in the .NET 3.5 Framework for Web Developers and Intro to ASP.NET MVC &#8211; 10:40am</strong></p>
<p><a title="Dr. Z" href="http://blogs.msdn.com/zxue" target="_blank">Zhiming Xue</a>, Architect Evangelist.</p>
<p>New features introduced in .NET 3.5 SP1: ADO.NET Entity Framework, ASP.NET Dynamic Data, ADO.NET Data Services, ASP.NET Routing.</p>
<p><strong><em>ADO.NET Entity Framework</em></strong></p>
<p>Microsoft&#8217;s 1st ORM offering for .NET.  Designed for providing a UI for ORM development.</p>
<ul>
<li>Entity Data Modle (EDM) separates objects from their Data Structures.  Objects are mapped to their physical data store via three things: Conceptual Schema Definition (CSDL), Storage Schema Definition (SSDL), and the Mapping Specification (MSL).  This approach decouples the DB Schema from the Application Model.  This provides flexibility and can be platform independent (requires an Entity Data Provider.)</li>
<li>Entity Framework is a set of services that allow you to consume EDM from within your applications.  It includes Object Services, Entity Client, EntitySQL, and Linq-to-Entities.</li>
<li>Visual Studio Support is supposed to make the development seamless and simple.</li>
</ul>
<p>DataSets are raw data store connections.  Linq To SQL provides an ADO.NET connection to SqlServer.  Entity Framework is going to allow ORM connections to most any database.</p>
<p>DEMO: Z wrote live a WPF application that consumes EDM.  Create a WPF solution.  Add a DLL project and  add a new ADO.NET Entity Model item to the project.  Select the data connection and store it in the Web.config file.  The database is diagrammed in Visual Studio, complete with relationships.  It also creates a Mapping Details window, which he did not demonstrate, but it looks like that is where you change the mapping.  The EDMX file contains the XML definition of the SSDL and CSDL.  Copy the App.Config file from the EDM project to the WPF project &#8211; this links the WPF to the correct Data Store.  Add an xxxEntities model object to instantiate the connection.  Very fast development, very impressive results in less than 5 minutes!</p>
<p><strong><em>ASP.NET Dynamic Data</em></strong></p>
<p>Data driven web application scaffolding.  If you are unfamiliar, scaffolding, popularized by Ruby on Rails, provides default pages for Insert, Update, Delete, etc.  DD is based on an object model with full controls, metadata, validation, etc.  This is expressed in two new ASP.NET project types: Entity Data Model and Linq To SQL.</p>
<p>DEMO: Z added a Dynamic Data Web Application to the above demo so that he could tie in to the same EDM code he already produced.  Set the connection stream in the Web.config file to connect the site to the EDM data store.  Apparently DD is set up assuming Linq, so Z had to make changes to the Page Templates to use the EDM instead.  He had to change LinqDataSource to EntityDataSource.  Then he had to register the EDM assembly within the individual pages.  (Couldn&#8217;t you do this once in Web.config?)</p>
<p>The default scaffolding is very nice and has all the features you would expect.  I saw a Routing mechanism, but he did not really discuss how it is used.  He demonstrated custom validation. It uses <em>System.ComponentModel.DataAnnotations</em> and implements events for validation.</p>
<p>Overall it looks interesting, but I&#8217;m not sure yet how it would be used in a real world setting.</p>
<p><strong><em>ADO.NET Data Services</em></strong></p>
<p>Formerly &#8220;Astoria&#8221;, this technology exposes data in a secure fashion over the web or network.  It is a combination of patterns and libraries that enable the creation and consumption of data services for the web as &#8220;feeds&#8221;.  This does not have to be a database: it can be any data source.</p>
<ul>
<li>Implemented as ATOM &#8211; tables = feeds, rows = entities.  Includes CRUD, is RESTful, and a URI points to a resource.</li>
<li>Uses common URL syntax</li>
<li>Capable of exposing any object model that contains IQueryable&lt;T&gt;, such as Linq to SQL and EDM.</li>
<li>Locked down by default and supports Operation Batching</li>
<li>Supports optimistic concurrency</li>
</ul>
<p>DEMO: Z added a ADO.NET Data Service item to the above Web project.  You have to update the service code to indicate what the model is and set some rules.  It was a lot of copy and paste and went by too quickly to document.  At this point he basically lost me.  He hard coded the port the service executed on.  He generated a file using DataServiceUTIL.exe (but never executed the app that I saw) and then copied the file into the WPF solution.  He added a reference in the XAML to the service and a pointer to the service in App.config.  He did finally get it working, and it is interesting, but again I&#8217;m not sure how I would use it.</p>
<p><em><strong>ASP.NET Routing</strong></em></p>
<p>Routing maps an application URL to specific handlers.  I have been using this in ASP.NET MVC for a while, and they have always said that this was not limited to MVC.  His example used <em>DynamicDataRoute()</em> instances.  At this point his time was running short, so he didn&#8217;t really go into a lot of details.</p>
<p><em><strong>ASP.NET MVC</strong></em></p>
<p>As we know, MVC has been in my sights for a while now, and I have been very pleased with the implementation.  To be fair to Z, he was really rushing to get through this because of time.  Unfortunately, I think he skipped a lot of important basics, but he did at least demo the default and the Task List projects.  He really skimmed over the project types, and in the long run I think he just confused anyone who was not already familiar with MVC.  Last but not least, he only mentioned that you could use Unit Testing, but did not demo it at all.</p>
<p><strong>AJAX Development and Troubleshooting &#8211; 1pm<br />
</strong></p>
<p>Andrew Duthie presenting.  AJAX is a system of lightweight calls to the server without having to repost the entire web page.  I have used AJAX extensively in ASP.NET MVC using <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a>.</p>
<p><strong><em>ASP.NET AJAX</em></strong></p>
<ul>
<li>Simple Development Framework</li>
<li>Represented as additional libraries to ASP.NET</li>
<li>Two Models:</li>
<li>UpdatePanel Control (zero code implementation)</li>
<li>ScriptManager Control (provides a rich framework of JavaScript libraries)</li>
</ul>
<p>Included with .NET 3.5.  AJAX Control Toolkit is a separate project available from CodePlex.  The AJAX libraries work on Windows, Mac OS, and Linux in IE, Firefox, Opera, Safari, and others.</p>
<p>DEMO:  Andrew created an AutoComplete textbox sample. Create a Web Form and add an AJAX Form to it, which automatically set up the ScriptManager.  Add a reference to the AjaxControlToolkit.  Now all the Extenders are available in the toolbox.  Drag an AutoCompleteExtender to the page and set up a few attributes to hook into a data source.  Viola!  Good demo.</p>
<p>AJAX updates in .NET 3.5 SP1:</p>
<ul>
<li>Browser History &#8211; allows an Ajax page to be bookmarked for future return (including page data)</li>
<li>Script Combining &#8211; batches a set of Scripts to be treated as a single download</li>
</ul>
<p><span style="text-decoration: underline;"><strong>ANNOUNCEMENT</strong></span>: <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a> will be included in all future versions of Visual Studio!  It is to be treated as a first class citizen, complete with <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a> support.  Microsoft will even have full PSS support.  ASP.NET MVC will be the first ship of this feature.</p>
<p><strong>AJAX Troublesooting</strong></p>
<p>While it is a great tool, Visual Studio is not enough.  You also need tools for CSS, DOM, and Scripting analysis.</p>
<ul>
<li><a title="IE Developer Toolbar" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.microsoft.com%2Fdownloads%2Fdetails.aspx%3Ffamilyid%3De59c3964-672d-4511-bb3e-2d5e1db91038&amp;ei=MWTiSIqzJoLsgwTz-5WXDA&amp;usg=AFQjCNEFCIZRv-rL_JZ9pmEOWIrgTNCy8A&amp;sig2=VxKq_Xim12ua5rI_nftojQ" target="_blank">The IE Developer Toolbar</a> allows you to drill down into your code and is especially good for IE 6 and IE7.  IE8 has built in developer tools including JavaScript debugging, dynamic CSS changes, and more.</li>
<li><a title="Firebug" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=https%3A%2F%2Faddons.mozilla.org%2Fen-US%2Ffirefox%2Faddon%2F1843&amp;ei=82PiSKHRA6SwgASDuIGQDA&amp;usg=AFQjCNGLyYT6w3IRt0w4Rt0DCyF1vfbgRA&amp;sig2=imqJYJ2Y5LVrIktdh3qK7g" target="_blank">Firebug</a> is a similar tool for Firefox.</li>
<li><a title="Firebug Lite" href="http://getfirebug.com/lite.html" target="_blank">Firebug Lite</a> is a tool that can be run without being installed (runs as a JavaScript app.)</li>
<li><a title="httpwatch" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.httpwatch.com%2F&amp;ei=sGTiSK-uMJ7MgQTq3rWODA&amp;usg=AFQjCNE9KsYnLY8TMWddUbyE-jSwWWxH8Q&amp;sig2=UpRC35joQi-oRREdM6C2HA" target="_blank">httpwatch</a> (IE and Firefox Only) &#8211; basic is free, pro costs money</li>
<li><a title="fiddler" href="http://www.fiddlertool.com/fiddler/" target="_blank">fiddler</a> &#8211; interaction record log</li>
</ul>
<p><em><strong>Other Frameworks</strong></em></p>
<ul>
<li><a title="The Dojo Toolkit" href="http://dojotoolkit.org/" target="_blank">The Dojo Toolkit</a></li>
<li><a title="Yahoo! UI" href="http://developer.yahoo.com/yui/" target="_blank">Yahoo! UI</a></li>
<li> <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a></li>
<li><a title="prototype" href="http://www.prototypejs.org/" target="_blank">prototype JavaScript Framework</a></li>
</ul>
<p>Andrew then spent the rest of the session showing some cool AJAX and JavaScript components.</p>
<p><strong>Microsoft Silverlight 2.0</strong></p>
<p>Ashish Jaiman, ISV Architect Evangelist</p>
<p>Silverlight is a cross browser, cross platform .NET plugin for delivering Rich Experiences in a browser.  Silverlight runs in the browser sandbox and executes .NET code.  Can be hosted in any container element in HTML.  HTML can be overlaid on top of Silverlight elements, and you can have many Silverlight components on a single page.</p>
<p>Silverlight 1.0 was only HTML and JavaScript.  Silverlight 2.0, on the other hand, includes a mini CLR, WPF controls, LINQ, collections, media, layout controls, and more.  Silverlight 2.0 has local storage, FileOpen capabilities, sockets, and cross domain HTTP requests.</p>
<p>Silverlight Pros:</p>
<ul>
<li>Video/Audio</li>
<li>Enhanced UX to increase stickiness</li>
<li>Decrease the learning curve</li>
<li>High resolution imagery</li>
<li>Data Visualization</li>
<li>Leverage .NET Skills for cross browser/cross platform solutions</li>
</ul>
<p>Silverlight Cons:</p>
<ul>
<li>Requires a browser plugin</li>
<li>There is still a learning curve</li>
<li>Need for designers to take full advantage</li>
</ul>
<p><strong>Designer and Developer Collaboration</strong></p>
<p>This brings up one of the main problems with WPF and Silverlight.  Microsoft&#8217;s belief is that developers should focus on developing data, communications, business rules, etc.  <em>Designers</em> should be the ones designing our user experiences.  As a one man shop, I can tell you that this isn&#8217;t going to happen, but I understand Microsoft&#8217;s point.</p>
<p>In order to really maximize the XAML abstraction concept, it will truly take a designer&#8217;s touch wrapped around a developer&#8217;s logic.  XAML is simply a description of a user interface in XML and contains no code.  A designer can then use tools like Expression Blend (2.5 for Silverlight 2.0) to design the interface, which will then export the design as XAML.  Visual Studio then can read the XAML and allow the developer to add any necessary application logic.  In fact, Blend and Visual Studio can be opened and used simultaneously against the same code, which is more realistic for someone in my shoes.</p>
<p>ASP.NET includes Silverlight support via the &lt;asp:xaml&gt; and &lt;asp:media&gt; tags, Silverlight has web-service support, and it can utilize the Membership, Profile, and Application Service integration.  IIS 7.0 also includes specific support for Silverlight.</p>
<p>Here is a pretty cool <a title="Silverlight demo" href="http://www.mscui.com/" target="_blank">Silverlight demo</a>.  (Go to the &#8220;Patient Journey Demonstrator&#8221;)</p>
<p>Styling and skinning are completely customizable, which is one of the main points of WPF technologies: however you can imagine visualizing your data or application, then you should be able to make it a reality in WPF/Silverlight.</p>
<p><em><strong>Local Storage</strong></em></p>
<p>&#8220;Cookies on steroids&#8221;, local storage provides 1MB of application specific local information.  Can be expanded if the user allows it.  Exposed through Microsoft Isolated Storage.</p>
<p><strong><em>DOM Integration</em></strong></p>
<p>Silverlight is still a browser application, so it can interact with and create HTML elements and scripts through .NET code.</p>
<p><em><strong>Open File Dialog</strong></em></p>
<p>You can use this to open a local file on the client.</p>
<p><em><strong>LINQ</strong></em></p>
<p>Silverlight 2.0 has LINQ support as part of its CLR.  Currently only on IEnumerable&lt;T&gt;, but XLINQ and DLINQ are in development.</p>
<p><em><strong>Data Acquisition</strong></em></p>
<p>Silverlight supports the following Methods:</p>
<ul>
<li>GET, POST,</li>
<li>Headers</li>
<li>Background threads</li>
<li>Streaming</li>
<li>Cross domain access (ClientAccess.xml, a subset of CrossDomain.xml)</li>
<li>WebClient and HttpWebRequest/Response</li>
</ul>
<p>The session ended when the instructor&#8217;s computer went belly up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/net/live-blogging-msdn-mid-atlantic-roadshow.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authorize.Net Code Release</title>
		<link>http://www.developingfor.net/free-code/authorizenet-code-release.html</link>
		<comments>http://www.developingfor.net/free-code/authorizenet-code-release.html#comments</comments>
		<pubDate>Mon, 29 Sep 2008 22:16:39 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[Free Code]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=116</guid>
		<description><![CDATA[Back in February I posted the beginnings of a project to wrap Authorize.Net credit card transactions in C# .NET code.  I have been working on this project off and on, in conjunction with a new website we are developing, and have been meaning to post the production version for some time.
Today, I am publishing [...]]]></description>
			<content:encoded><![CDATA[<p>Back in February I posted the <a title="Authorize.Net" href="http://www.developingfor.net/miscellaneous/authorizenet-c-code.html" target="_self">beginnings of a project to wrap Authorize.Net</a> credit card transactions in C# .NET code.  I have been working on this project off and on, in conjunction with a new website we are developing, and have been meaning to post the production version for some time.</p>
<p>Today, I am publishing the current version of the code, <a title="Authorize.Net" href="DevelopingForDotNet.AuthorizeNet" target="_self">DevelopingForDotNet.AuthorizeNet</a>, along with a few supporting updates.  I&#8217;d like to thank everyone who posted comments on that entry and the <a title="First Foray into Unit Testing" href="http://www.developingfor.net/visual-studio/first-foray-into-unit-testing-with-visual-studio-2008.html" target="_self">First Foray into Unit Testing</a> entry.  Most of those suggestions made it into the final version and I learned a lot about Unit Testing along the way.</p>
<p>This version is slightly different than the original post.  Here are the major differences:</p>
<p><strong>Validity Checking</strong></p>
<p>This version incorporates validity checking on the following <em>TransactionRequest</em> class properties:</p>
<ul>
<li>EMail</li>
<li>Zip</li>
<li>SecurityCode</li>
<li>CardNumber</li>
<li>ExpDate</li>
</ul>
<p><em>EMail</em>, <em>CardNumber</em>, and <em>ExpDate</em> validation have been completely rewritten.</p>
<p><em>ExpDate</em> now accepts the following formats:</p>
<ul>
<li>MMYY</li>
<li>MM/YY</li>
<li>MM-YY</li>
<li>MMYYYY</li>
<li>MM/YYYY</li>
<li>MM-YYYY</li>
</ul>
<p>The Validity Checking uses a set of Regular Expression patterns that I have put into another namespace, <a title="Regex Support" href="http://www.developingfor.net/free-code/developingfordotnetregexsupport" target="_self">DevelopingForDotNet.RegexSupport</a>.  It will be available on the <a title="Free Code" href="http://www.developingfor.net/free-code" target="_self">Free Code</a> page as well.</p>
<p>Right now, all the failures throw an <em>ArgumentException</em>, which is very heavy handed but I haven&#8217;t had a need to improve it yet.</p>
<p><strong>INotifyPropertyChanged</strong></p>
<p>Each of the three classes implements <em>INotifyPropertyChanged</em> so you can use them for data binding if you wish.  If you have never implemented this interface before, it is very easy.  Add a reference to <em>System.ComponentModel</em> to your code. Then add the inheritance statement to your class:</p>
<div class="dean_ch" style="white-space: nowrap;">public class TransactionRequestInfo : INotifyPropertyChanged<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &#8230;<br />
<span class="br0">&#125;</span></div>
<p>Then implement the <em>PropertyChangedEventHandler</em> and add a method to fire the event:</p>
<div class="dean_ch" style="white-space: nowrap;">public event PropertyChangedEventHandler PropertyChanged;</p>
<p>protected <span class="kw4">void</span> OnPropertyChanged<span class="br0">&#40;</span><span class="kw4">string</span> propertyName<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>this.<span class="me1">PropertyChanged</span> != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; PropertyChanged<span class="br0">&#40;</span>this, new PropertyChangedEventArgs<span class="br0">&#40;</span>propertyName<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Then call the method whenever a property changes:</p>
<div class="dean_ch" style="white-space: nowrap;">public <span class="kw4">string</span> FirstName<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> _first; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _first = value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; OnPropertyChanged<span class="br0">&#40;</span><span class="st0">&quot;FirstName&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Easy as can be!</p>
<p><strong>Transaction.ProcessPayment</strong></p>
<p><em>Transaction</em> is a static class with <em>ProcessPayment</em> as its single static method.  In reviewing the project, I realized that this was a perfect case for an Extension Method, so I added <em>this</em> before the first keyword, and now calling the method is even nicer than before:</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="co1">// Account is built above&#8230;</span><br />
TransactionResponseInfo pmtResponse = pmtInfo.<span class="me1">ProcessPayment</span><span class="br0">&#40;</span>Account<span class="br0">&#41;</span>;</div>
<p><strong>Unit Testing</strong></p>
<p>I really got my feet wet with Unit Testing on this project.  I followed the <a title="Freekshow - Unit Testing" href="http://freekleemhuis.wordpress.com/2008/06/26/unit-testing-with-visual-studio-2008-part-2/" target="_blank">advice I got from FreekShow</a> and implemented the testing of Exceptions in a much cleaner fashion.  The whole experience got me thinking about why Unit Testing is so beneficial, and as I began rewriting the code I started by writing tests that fail first and then coding my way into success.  Just for grins, the testing project for this solution is included in the download.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/free-code/authorizenet-code-release.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Extensions update and new Namespace added to Free Code</title>
		<link>http://www.developingfor.net/free-code/extensions-update-and-new-namespace-added-to-free-code.html</link>
		<comments>http://www.developingfor.net/free-code/extensions-update-and-new-namespace-added-to-free-code.html#comments</comments>
		<pubDate>Mon, 29 Sep 2008 21:59:23 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[Free Code]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=122</guid>
		<description><![CDATA[In support of the Authorize.Net project, I have updated the Free Code page:

DevelopingForDotNet.Extensions &#8211; updated with many new Extension Methods.
DevelopingForDotNet.RegexSupport &#8211; contains a list of useful Regular Expression Patterns.

]]></description>
			<content:encoded><![CDATA[<p>In support of the Authorize.Net project, I have updated the <a title="Free Code" href="http://www.developingfor.net/free-code" target="_self">Free Code</a> page:</p>
<ul>
<li><a title="Extension Methods" href="http://www.developingfor.net/free-code/developingfordotnetextensions" target="_self">DevelopingForDotNet.Extensions</a> &#8211; updated with many new Extension Methods.</li>
<li><a title="Regex Support" href="http://www.developingfor.net/free-code/developingfordotnetregexsupport" target="_self">DevelopingForDotNet.RegexSupport</a> &#8211; contains a list of useful Regular Expression Patterns.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/free-code/extensions-update-and-new-namespace-added-to-free-code.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[REPOST] &#8211; RVNUG May 2008</title>
		<link>http://www.developingfor.net/net-35/rvnug-may-2008.html</link>
		<comments>http://www.developingfor.net/net-35/rvnug-may-2008.html#comments</comments>
		<pubDate>Fri, 06 Jun 2008 20:32:21 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=95</guid>
		<description><![CDATA[Last night I attended the monthly RVNUG (Roanoke Valley .NET User’s Group) meeting. Kevin Hazzard gave a good presentation on Silverlight 2.0, which I have been eager to try. After what I saw last night, and now that I have a little experience with WPF, I am even more eager to give it a shot. [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I attended the monthly <a title="RVNUG" href="http://www.rvnug.org/" target="_blank">RVNUG</a> (Roanoke Valley .NET User’s Group) meeting. <a title="Kevin Hazzard" href="http://gotnet.biz/" target="_blank">Kevin Hazzard</a> gave a good presentation on <a title="Silverlight" href="http://silverlight.net/" target="_blank">Silverlight</a> 2.0, which I have been eager to try. After what I saw last night, and now that I have a little experience with WPF, I am even more eager to give it a shot. What I am not eager to do is what I saw last night, and that is Silverlight development in Visual Studio. More specifically, I have no desire to hand code XAML, which is why I like Blend so much.</p>
<p>Today I’ll be downloading and installing the <a title="Silverlight 2.0 Beta 1 Tools for Visual Studio" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E0BAE58E-9C0B-4090-A1DB-F134D9F095FD&amp;displaylang=en" target="_blank">Silverlight 2.0 Beta 1 Tools</a>, and I may install <a title="Blend 2.5 Preview" href="http://www.microsoft.com/expression/products/download.aspx?key=blend2dot5" target="_blank">Blend 2.5 Preview</a> (which I hear is far from rady for prime time). I’ll be putting together a couple Silverlight samples in the next week or so. If I come up with anything interesting, I’ll be sure to share it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/net-35/rvnug-may-2008.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[REPOST] &#8211; Local Method Practical Example</title>
		<link>http://www.developingfor.net/net-35/local-method-practical-example.html</link>
		<comments>http://www.developingfor.net/net-35/local-method-practical-example.html#comments</comments>
		<pubDate>Fri, 06 Jun 2008 20:31:55 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=94</guid>
		<description><![CDATA[I recently wrote about the idea of using Generic Delegates to create Local Methods (methods wholly defined within the scope of another method). Today, I had a practical application for this technique so I wanted to share it.
In this example, our task is to build a portion of an SQL update string that contains only [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wrote about the idea of <a title="Local Methods" href="../net-35/creating-local-methods-with-func.html" target="_self">using Generic Delegates to create Local Methods</a> (methods wholly defined within the scope of another method). Today, I had a practical application for this technique so I wanted to share it.</p>
<p>In this example, our task is to build a portion of an SQL update string that contains only the fields within a class that have been changed. The class stores original values and current values, so finding the changed fields is a simple matter of comparison. We are going to use a <em>StringBuilder</em> to construct the string. The problem comes in properly appending a comma between each name-value pair string. You cannot always add one after adding a new string since it may be the last, so the solution is to check the length of the <em>StringBuilder</em> before appending the string: if it is greater than 0, then we append a comma first.</p>
<p>The task is simple enough, but what we end up with is a lot of redundant code:</p>
<div class="dean_ch" style="white-space: nowrap;">StringBuilder updateString = new StringBuilder<span class="br0">(</span><span class="br0">)</span>;<br />
<span class="kw1">if</span> <span class="br0">(</span>this.<span class="me1">FIELD1</span> != this.<span class="me1">o_FIELD1</span> <span class="br0">)</span><br />
<span class="br0">{</span><br />
updateString.<span class="me1">Append</span><span class="br0">(</span> <span class="st0">&#8220;FIELD1 = ‘&#8221;</span> + this.<span class="me1">FIELD1</span> + <span class="st0">&#8220;’&#8221;</span> <span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="kw1">if</span> <span class="br0">(</span>updateString.<span class="me1">Length</span> &gt; <span class="nu0">0</span><span class="br0">)</span><br />
<span class="br0">{</span><br />
updateString.<span class="me1">Append</span><span class="br0">(</span><span class="st0">&#8220;,&#8221;</span><span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="kw1">if</span> <span class="br0">(</span>this.<span class="me1">FIELD2</span> != this.<span class="me1">o_FIELD2</span> <span class="br0">)</span><br />
<span class="br0">{</span><br />
updateString.<span class="me1">Append</span><span class="br0">(</span> <span class="st0">&#8220;FIELD2 = ‘&#8221;</span> + this.<span class="me1">FIELD2</span> + <span class="st0">&#8220;’&#8221;</span> <span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="kw1">if</span> <span class="br0">(</span>updateString.<span class="me1">Length</span> &gt; <span class="nu0">0</span><span class="br0">)</span><br />
<span class="br0">{</span><br />
updateString.<span class="me1">Append</span><span class="br0">(</span><span class="st0">&#8220;,&#8221;</span><span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="kw1">if</span> <span class="br0">(</span>this.<span class="me1">FIELD3</span> != this.<span class="me1">o_FIELD3</span> <span class="br0">)</span><br />
<span class="br0">{</span><br />
updateString.<span class="me1">Append</span><span class="br0">(</span> <span class="st0">&#8220;FIELD3 = ‘&#8221;</span> + this.<span class="me1">FIELD3</span> + <span class="st0">&#8220;’&#8221;</span> <span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="kw1">if</span> <span class="br0">(</span>updateString.<span class="me1">Length</span> &gt; <span class="nu0">0</span><span class="br0">)</span><br />
<span class="br0">{</span><br />
updateString.<span class="me1">Append</span><span class="br0">(</span><span class="st0">&#8220;,&#8221;</span><span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="co1">// Etc.</span></div>
<p>As you can see, this repeatedly defines the same behavior. It is especially aggravating when dealing with some of our legacy database tables that have hundreds of fields. While it may not be likely in this example, if we had to change this behavior it would be very tedious and some changes could easily be missed. This action is only relevant within the context of our Update method, so I really don’t want to outsource this to a private class method. Instead I will use a Generic Delegate to create a Local Method.</p>
<p>Since I am updating a local variable, I really don’t need to pass it: I’m going to take advantage of local variable access to reduce the parameter list and simplify the method signature. I do not need a return value, so I am going to use <em>Action&lt;T&gt;</em> to define a method that accepts a string and appends it to the <em>StringBuilder</em> and handles the commas as necessary. To ensure I can access the desired <em>StringBuilder</em> variable, I need to define it before defining my Local Method:</p>
<div class="dean_ch" style="white-space: nowrap;">StringBuilder updateString = new StringBuilder<span class="br0">(</span><span class="br0">)</span>;<br />
Action AppendUpdateString = new Action<span class="br0">(</span>s =&gt;<br />
<span class="br0">{</span><br />
<span class="kw1">if</span> <span class="br0">(</span>updateString.<span class="me1">Length</span> &gt; <span class="nu0">0</span><span class="br0">)</span><br />
<span class="br0">{</span><br />
updateString.<span class="me1">Append</span><span class="br0">(</span><span class="st0">&#8220;,&#8221;</span><span class="br0">)</span>;<br />
<span class="br0">}</span><br />
updateString.<span class="me1">Append</span><span class="br0">(</span>s<span class="br0">)</span>;<br />
<span class="br0">}</span><span class="br0">)</span>;</div>
<p>Now, I simply call the method at each desired instance (also defined after the Local Method declaration):</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="kw1">if</span><span class="br0">(</span>this.<span class="me1">FIELD1</span> != this.<span class="me1">o_FIELD1</span> <span class="br0">)</span><br />
<span class="br0">{</span><br />
AppendUpdateString<span class="br0">(</span> <span class="st0">&#8220;FIELD1 = ‘&#8221;</span> + this.<span class="me1">FIELD1</span> + <span class="st0">&#8220;’&#8221;</span> <span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="kw1">if</span> <span class="br0">(</span>this.<span class="me1">FIELD2</span> != this.<span class="me1">o_FIELD2</span> <span class="br0">)</span><br />
<span class="br0">{</span><br />
AppendUpdateString<span class="br0">(</span> <span class="st0">&#8220;FIELD2 = ‘&#8221;</span> + this.<span class="me1">FIELD2</span> + <span class="st0">&#8220;’&#8221;</span> <span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="kw1">if</span> <span class="br0">(</span>this.<span class="me1">FIELD3</span> != this.<span class="me1">o_FIELD3</span> <span class="br0">)</span><br />
<span class="br0">{</span><br />
AppendUpdateString<span class="br0">(</span> <span class="st0">&#8220;FIELD3 = ‘&#8221;</span> + this.<span class="me1">FIELD3</span> + <span class="st0">&#8220;’&#8221;</span> <span class="br0">)</span>;<br />
<span class="br0">}</span><br />
<span class="co1">// Etc.</span></div>
<p>And this code could probably be simplified a little more, but I think this is adequate to the task. Hopefully, you’ll agree that this technique has merit. It’s very clean and easy to implement. I really like this, so much so that I am going to need to be careful to take my own advice and not go crazy with this approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/net-35/local-method-practical-example.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[REPOST] &#8211; Creating Local Methods with Func</title>
		<link>http://www.developingfor.net/net-35/creating-local-methods-with-func.html</link>
		<comments>http://www.developingfor.net/net-35/creating-local-methods-with-func.html#comments</comments>
		<pubDate>Fri, 06 Jun 2008 20:29:24 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=90</guid>
		<description><![CDATA[I wrote briefly about the new Func generic delegate in Part 3 of the Upgrade your C# Skills series. Today, I wanted to explore this in a little more detail.
I’m sure that most of us have created many private methods to outsource code from one method to another. There are times we do this even [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote briefly about the new <em>Func</em> generic delegate in <a title="Upgrade your C# Skills part 3 - Lambda Expressions" href="../c-30/upgrade-your-c-skills-part-3-lambda-expressions.html" target="_self">Part 3 of the Upgrade your C# Skills</a> series. Today, I wanted to explore this in a little more detail.</p>
<p>I’m sure that most of us have created many private methods to outsource code from one method to another. There are times we do this even when the method is only called from a single location. I’m going to use a simple example, but I think you’ll get the point:</p>
<div class="dean_ch" style="white-space: nowrap;">foreach <span class="br0">(</span>Person person in people<span class="br0">)</span><br />
<span class="br0">{</span>DateTime now = DateTime.<span class="me1">Now</span>;<br />
<span class="kw4">int</span> age = now.<span class="me1">Year</span> &#8211; person.<span class="me1">Age</span>;</p>
<p>Console.<span class="me1">WriteLine</span><span class="br0">(</span><span class="st0">&#8220;{0} {1} was probably born in {2}.&#8221;</span>,<br />
person.<span class="me1">FirstName</span>,<br />
person.<span class="me1">LastName</span>,<br />
age<span class="br0">)</span>;<br />
<span class="br0">}</span></p>
</div>
<p>Kind of a silly example, but fairly straight forward stuff, right? Well, what if we had two loops or other calculations <strong>in the same method</strong> that needed to know the Year born? Since we believe in code reuse, we would typically throw this into its own private method:</p>
<div class="dean_ch" style="white-space: nowrap;">foreach <span class="br0">(</span>Person person in people<span class="br0">)</span><br />
<span class="br0">{</span><br />
Console.<span class="me1">WriteLine</span><span class="br0">(</span><span class="st0">&#8220;{0} {1} was probably born in {2}.&#8221;</span>,<br />
person.<span class="me1">FirstName</span>,<br />
person.<span class="me1">LastName</span>,<br />
CalculateYearBorn<span class="br0">(</span>person<span class="br0">)</span><span class="br0">)</span>;<br />
<span class="br0">}</span>…</p>
<p><span class="me1">private</span><span class="kw4">int</span> CalculateYearBorn<span class="br0">(</span>Person person<span class="br0">)</span><br />
<span class="br0">{</span><br />
DateTime now = DateTime.<span class="me1">Now</span>;<br />
<span class="kw4">int</span> age = now.<span class="me1">Year</span> &#8211; person.<span class="me1">Age</span>;<br />
<span class="kw1">return</span> age;<br />
<span class="br0">}</span></p>
</div>
<p>This should be code we can all relate to, and is a fine practice because it accomplishes two very important things. First, it promotes code reuse. Second, it simplifies and cleans up our logic. What unfortunately happens quite frequently is that the outsourced method is only called from one other method, even if it is multiple times. In this scenario, what we really need is a <em>Local Method</em>.</p>
<p><strong>Local Methods</strong></p>
<p>I don’t know if anyone else has coined this phrase before in this context, but it seems appropriate. A quick <a title="Google Search" href="http://www.google.com/search?source=ig&amp;hl=en&amp;rlz=&amp;q=%22Local+method%22&amp;btnG=Google+Search" target="_blank">google search</a> turned up several references to Java and some statistical analysis looking items. Adding the “C#” to the search terms found a couple of references where the term is misapplied to mean a private class method. To be clear, though, what I mean by <em>Local Method</em> is a method defined completely within a non-class parent scope. If you think about it, that’s what Anonymous Delegates are, but unlike an anonymous delegate, we need to be able to assign our method a name. The <em>Func&lt;&gt;</em> Generic Delegate can be used to accomplish this goal.</p>
<p>This approach is going to give us the best of both worlds. First, it is going to allow us to reuse code. Second, it is going to clean up our execution logic by replacing some of it (or maybe even all of it) with a method call. Finally, it is going to help reduce “Class clutter” by eliminating private methods that are only called from one location.</p>
<p><strong>Creating and Using the Local Method</strong></p>
<p>In order to use the local method, we first need to define it as a local variable. This local variable is of type <em>Func&lt;&gt;</em>, which has several different signatures. We are going to use <em>Func&lt;Person, int&gt;</em> to create a method that accepts a Person object as a parameter and returns an int:</p>
<div class="dean_ch" style="white-space: nowrap;">Func&lt;Person, int&gt; CalculateYearBorn = new Func&lt;Person,int&gt;<span class="br0">(</span><br />
delegate <span class="br0">(</span>Person per<span class="br0">)</span><br />
<span class="br0">{</span><br />
DateTime now = DateTime.<span class="me1">Now</span>;<br />
<span class="kw4">int</span> age = now.<span class="me1">Year</span> &#8211; per.<span class="me1">Age</span>;<br />
<span class="kw1">return</span> age;<br />
<span class="br0">}</span><span class="br0">)</span>;</div>
<p>Now, to use the local method, we simply call it like we would any other:</p>
<div class="dean_ch" style="white-space: nowrap;">foreach <span class="br0">(</span>Person person in people<span class="br0">)</span><br />
<span class="br0">{</span><br />
Console.<span class="me1">WriteLine</span><span class="br0">(</span><span class="st0">&#8220;{0} {1} was probably born in {2}.&#8221;</span>,<br />
person.<span class="me1">FirstName</span>,<br />
person.<span class="me1">LastName</span>,<br />
CalculateYearBorn<span class="br0">(</span>person<span class="br0">)</span><span class="br0">)</span>;<br />
<span class="br0">}</span></div>
<p>I think you’ll agree that this is pretty cool and could be very useful. And of course, since this is based on a Generic Delegate, we can use <a title="Upgrade your C# Skills part 3 - Lambda Expressions" href="../c-30/upgrade-your-c-skills-part-3-lambda-expressions.html" target="_self">Lambda Expressions</a> to write our code. So even though this is a fairly silly example, let’s go ahead and clean it up a bit:</p>
<div class="dean_ch" style="white-space: nowrap;">Func&lt;Person, int&gt; CalculateYearBorn =<br />
new Func&lt;Person, int&gt;<span class="br0">(</span>per =&gt; <span class="br0">{</span> <span class="kw1">return</span> DateTime.<span class="me1">Now</span>.<span class="me1">Year</span> &#8211; per.<span class="me1">Age</span>; <span class="br0">}</span><span class="br0">)</span>;people.<span class="me1">ForEach</span><span class="br0">(</span>person =&gt; Console.<span class="me1">WriteLine</span><span class="br0">(</span><span class="st0">&#8220;{0} {1} was probably born in {2}.&#8221;</span>,<br />
person.<span class="me1">FirstName</span>,<br />
person.<span class="me1">LastName</span>,<br />
CalculateYearBorn<span class="br0">(</span>person<span class="br0">)</span><span class="br0">)</span><span class="br0">)</span>;</p>
</div>
<p><strong>Some Final Notes</strong></p>
<p>I really like this approach, but it naturally does not suit every purpose, so rule one, to paraphrase Sean Connery in <em>The Untouchables</em>, “don’t bring a knife to a gun fight.” In other words, don’t go crazy and use this just because you can. Use it to minimize repeated code within a specific method or to simplify complex code blocks.</p>
<p>There are a couple of additional things you should know. First, you must define the delegate and method details before using them, otherwise the compiler will complain. Second, since this is a local method it has complete access to the other local method variables: this should help reduce the number of parameters you must send in order to accomplish your task. Finally, since the local method is actually a local variable itself, you should be able to change the address dynamically to other delegates. I don’t think I would recommend this last item, but it could prove to be interesting experimentation fodder.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/net-35/creating-local-methods-with-func.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Object Initializers on Dictionary</title>
		<link>http://www.developingfor.net/c-30/using-object-initializers-on-dictionary.html</link>
		<comments>http://www.developingfor.net/c-30/using-object-initializers-on-dictionary.html#comments</comments>
		<pubDate>Fri, 14 Mar 2008 00:19:12 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C# 3.0]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/c-30/using-object-initializers-on-dictionary.html</guid>
		<description><![CDATA[I&#8217;m still going strong on the ASP.NET MVC development, and I wanted to experiment with HtmlHelper.Select rather than hard coding specific values into my View.  To that end, I am building a supporting class that will retain static properties (which I&#8217;m sure will be cached once I figure out how to do that).  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m still going strong on the <a href="http://www.developingfor.net/category/aspnet-mvc" title="ASP.NET MVC">ASP.NET MVC</a> development, and I wanted to experiment with <em>HtmlHelper.Select</em> rather than hard coding specific values into my View.  To that end, I am building a supporting class that will retain static properties (which I&#8217;m sure will be cached once I figure out how to do that).  Some of these properties are lists of information, like product types and prices, that could be fed from a database table.  Others may be static lists with the potential to become database driven, like state codes and names.  Ultimately, where they come from does not matter, but in my coding today I came across something interesting.</p>
<p>To begin this process, I decided to populate a static <em>Dictionary&lt;string, string&gt;</em> with  a list of codes and values.  This is a small list, so for initial testing I just wanted to hard code the values.  It has become a habit for me to use <a href="http://www.developingfor.net/c-30/upgrade-your-c-skills-part-2-compiler-inference-object-initializers-and-anonymous-types.html" title="Upgrade your C# Skills part 2">Object Initializers</a> whenever possible, so naturally this seemed a perfect fit.  But let me ask you: have you ever tried this?  I have to admit that at first I was a little stumped.  I first tried to build a method tree (a concept that really doesn&#8217;t exist in C#):</p>
<div class="dean_ch" style="white-space: nowrap;">
BusinessTypes = new Dictionary&lt;string, string&gt;<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;APP&quot;</span>, <span class="st0">&quot;Appraisal&quot;</span><span class="br0">&#41;</span><br />
.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;GOV&quot;</span>, <span class="st0">&quot;Government&quot;</span><span class="br0">&#41;</span><br />
.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;INS&quot;</span>, <span class="st0">&quot;Insurance&quot;</span><span class="br0">&#41;</span><br />
.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;LAW&quot;</span>, <span class="st0">&quot;Legal&quot;</span><span class="br0">&#41;</span><br />
.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;LEN&quot;</span>, <span class="st0">&quot;Lending&quot;</span><span class="br0">&#41;</span><br />
.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;REL&quot;</span>, <span class="st0">&quot;Real Estate&quot;</span><span class="br0">&#41;</span><br />
.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;RES&quot;</span>, <span class="st0">&quot;Research&quot;</span><span class="br0">&#41;</span><br />
.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;OTH&quot;</span>, <span class="st0">&quot;Other&quot;</span><span class="br0">&#41;</span>;</div>
<p>Even though I didn&#8217;t really expect this to work, I thought it would be interesting to see what happened. [This could be a good candidate for a future language enhancement.] Naturally it failed, but in an unexpected fashion.  The first call to .Add passed the compiler, but the <em>second</em> call to .Add threw the following error:</p>
<p><em>Operator &#8216;.&#8217; cannot be applied to operand of type &#8216;void&#8217;</em></p>
<p>I also tried adding the method call inside the Initializer block, but since you can&#8217;t put method calls inside of Initializer blocks I pretty much knew that wouldn&#8217;t work either.</p>
<p>So I looked at it some more and asked myself &#8220;what is the Dictionary looking for?&#8221;  My answer was &#8220;a <em>KeyValuePair&#8221;, so I tried that next:</em></p>
<div class="dean_ch" style="white-space: nowrap;">
BusinessTypes = new Dictionary&lt;string,&gt;<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; new &lt;u style=<span class="st0">&quot;display:none&quot;</span>&gt;&lt;a href=<span class="st0">&quot;http://2nddown.com/wp-content/1/fast-cash-payday-loan.html&quot;</span>&gt;payday us fast cash loan,fast cash payday loan&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://2nddown.com/wp-content/1/cash-loan-payday.html&quot;</span>&gt;cash till payday loan,cash loan payday,advance cash cash loan payday payday&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://2nddown.com/wp-content/1/loan-oneclickcash-payday.html&quot;</span>&gt;loan oneclickcash payday&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://2nddown.com/wp-content/1/cash-fast-loan-payday.html&quot;</span>&gt;cash fast loan payday&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://2nddown.com/wp-content/1/cash-advance-loan-illinois.html&quot;</span>&gt;cash advance loan illinois,<span class="nu0">5</span> advance cash illinois loan&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/full-pay-video-poker.html&quot;</span>&gt;full pay video poker&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/best-video-poker.html&quot;</span>&gt;best video poker&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/internet-casino.html&quot;</span>&gt;internet casino craps,internet casino,internet casino gambling game&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/free-online-casino-gambling.html&quot;</span>&gt;free online casino gambling&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/duces-wild-video-poker.html&quot;</span>&gt;duces wild video poker&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/casino-link-online-suggest.html&quot;</span>&gt;casino link online suggest&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/online-casino-bonus.html&quot;</span>&gt;no deposit bonus online casino,free online gambling casino bonus,online casino bonus&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/play-blackjack-online-free.html&quot;</span>&gt;play blackjack online free&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/free-video-poker-games.html&quot;</span>&gt;free video poker games&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/free-online-craps.html&quot;</span>&gt;craps free online play,casino craps free gambling online,free online craps&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/online-casino.html&quot;</span>&gt;free online casino,online casino,top online casino&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/playing-blackjack.html&quot;</span>&gt;playing blackjack&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/play-free-casino.html&quot;</span>&gt;play free casino&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/casino-cash.html&quot;</span>&gt;free casino cash bonus,casino cash,free cash casino&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/free-video-poker-game.html&quot;</span>&gt;free video poker game&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/real-money-backgammon.html&quot;</span>&gt;real money backgammon&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/play-roulette-online.html&quot;</span>&gt;play roulette online&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/free-casino-money.html&quot;</span>&gt;free casino money&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/triple-play-video-poker.html&quot;</span>&gt;triple play video poker&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/free-roulette.html&quot;</span>&gt;free roulette,free roulette download,play free roulette&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/roulette-gambling.html&quot;</span>&gt;roulette gambling,best gambling online roulette,online roulette gambling&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/play-black-jack-online-free.html&quot;</span>&gt;play black jack online free&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/online-gambling-casino.html&quot;</span>&gt;online gambling casino,gambling casino online bonus,free online casino gambling&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/casino-download.html&quot;</span>&gt;casino download,free online casino download,download online casino game&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/microgaming-casino-bonus.html&quot;</span>&gt;microgaming casino bonus&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/baccarat-game.html&quot;</span>&gt;baccarat card game,baccarat game,baccarat the internet casino game&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/casino-bonus.html&quot;</span>&gt;casino no deposit bonus code,online casino sign up bonus,casino bonus&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/video-poker-for-winners.html&quot;</span>&gt;video poker <span class="kw1">for</span> winners&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/video-poker.html&quot;</span>&gt;video poker strategy,free video poker,video poker&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/keno-game.html&quot;</span>&gt;keno game&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/play-slots.html&quot;</span>&gt;play slots,play <span class="kw1">for</span> fun online slots,free slots play <span class="kw1">for</span> free&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/craps-rules.html&quot;</span>&gt;craps rules&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/free-slots.html&quot;</span>&gt;play free slots,free slots,free online slots game&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/international-online-casino.html&quot;</span>&gt;international online casino&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/video-poker-machines.html&quot;</span>&gt;video poker machines&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/hand-held-video-poker.html&quot;</span>&gt;hand held video poker&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/gambling-craps.html&quot;</span>&gt;craps gambling strategy,craps gambling game,gambling craps&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/best-casino-bonus.html&quot;</span>&gt;best casino bonus&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/888-black-jack.html&quot;</span>&gt;<span class="nu0">888</span> black jack&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/free-slots-no-download.html&quot;</span>&gt;free online slots no download,no download free slots game,free slots no download&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/black-jack-download.html&quot;</span>&gt;black jack download&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/play-casino-game-online.html&quot;</span>&gt;play casino game online&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/tournament-backgammon.html&quot;</span>&gt;tournament backgammon&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/888-poker.html&quot;</span>&gt;<span class="nu0">888</span> poker,<span class="nu0">888</span> poker info,<span class="nu0">888</span> poker tournament&lt;/a&gt;&lt;a href=<span class="st0">&quot;http://blog.9810.rotary.org.au/wp-content/1/best-online-casino-bonus.html&quot;</span>&gt;best online casino bonus&lt;/a&gt;&lt;/u&gt; KeyValuePair&lt;string, string&gt;<span class="br0">&#40;</span><span class="st0">&quot;APP&quot;</span>, <span class="st0">&quot;Appraisal&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; new KeyValuePair&lt;string, string&gt;<span class="br0">&#40;</span><span class="st0">&quot;GOV&quot;</span>, <span class="st0">&quot;Government&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; new KeyValuePair&lt;string, string&gt;<span class="br0">&#40;</span><span class="st0">&quot;INS&quot;</span>, <span class="st0">&quot;Insurance&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; new KeyValuePair&lt;string, string&gt;<span class="br0">&#40;</span><span class="st0">&quot;LAW&quot;</span>, <span class="st0">&quot;Legal&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; new KeyValuePair&lt;string, string&gt;<span class="br0">&#40;</span><span class="st0">&quot;LEN&quot;</span>, <span class="st0">&quot;Lending&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; new KeyValuePair&lt;string, string&gt;<span class="br0">&#40;</span><span class="st0">&quot;REL&quot;</span>, <span class="st0">&quot;Real Estate&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; new KeyValuePair&lt;string, string&gt;<span class="br0">&#40;</span><span class="st0">&quot;RES&quot;</span>, <span class="st0">&quot;Research&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; new KeyValuePair&lt;string, string&gt;<span class="br0">&#40;</span><span class="st0">&quot;OTH&quot;</span>, <span class="st0">&quot;Other&quot;</span><span class="br0">&#41;</span><br />
<span class="br0">&#125;</span>;<br />
&lt;/<span class="kw4">string</span>,&gt;</div>
<p>That also threw an error:</p>
<p><em>No overload for method &#8216;Add&#8217; takes &#8216;1&#8242; arguments</em></p>
<p>But the error pointed me back to my original idea: somehow I needed to use Add(), but how?  And then it dawned on me: what the message is <em>really</em> telling me is that I was already using Add(), I just didn&#8217;t realize it!  Since we use curly braces to denote Initializers, I decided to try that within the context of the parent Initializer to send parmameters to the Add method:</p>
<div class="dean_ch" style="white-space: nowrap;">
BusinessTypes = new Dictionary&lt;string, string&gt;<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;APP&quot;</span>, <span class="st0">&quot;Appraisal&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;GOV&quot;</span>, <span class="st0">&quot;Government&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;INS&quot;</span>, <span class="st0">&quot;Insurance&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;LAW&quot;</span>, <span class="st0">&quot;Legal&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;LEN&quot;</span>, <span class="st0">&quot;Lending&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;REL&quot;</span>, <span class="st0">&quot;Real Estate&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;RES&quot;</span>, <span class="st0">&quot;Research&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;OTH&quot;</span>, <span class="st0">&quot;Other&quot;</span><span class="br0">&#125;</span><br />
<span class="br0">&#125;</span>;</div>
<p>This compiles fine and now I have successfully used an Object Initializer on a <em>Dictionary&lt;TKey, TValue&gt;</em> object.  I was curious about why this works, so I hit the Google pavement and found <a href="http://blogs.msdn.com/madst/archive/2006/10/10/What-is-a-collection_3F00_.aspx" title="MSDN Article" target="_blank">this article on MSDN</a> from October of 2006. In it, the author has this to say:</p>
<blockquote><p><font color="#000080" face="Verdana">Our resolution to this is to refine our understanding of collection initializers a little bit. The list you provide is not a list of elements to add, but a list of sets of arguments to </font><span class="Codeinline"><font color="#008000" face="Lucida Console">Add</font></span><font color="#000080" face="Verdana"> methods. If an entry in the list consists of multiple arguments to an </font><span class="Codeinline"><font color="#008000" face="Lucida Console">Add</font></span><font color="#000080" face="Verdana"> method, these are enclosed in </font><span class="Codeinline"><font color="#008000" face="Lucida Console">{</font></span><font color="#000080" face="Verdana"> curly braces </font><span class="Codeinline"><font color="#008000" face="Lucida Console">}</font></span><font color="#000080" face="Verdana">. This is actually immensely useful. For example, it allows you to<span> </span><span class="Codeinline"><font color="#008000" face="Lucida Console">Add</font></span> key/value pairs to a dictionary, something we have had a number of requests for as a separate feature.</font></p></blockquote>
<p>From previous text in the article, we find that any IEnumerable with a public Add method will behave this way.  As such, we should be able to use this construct in almost all the generic Collection classes.</p>
<p>This is definitely useful, and yes I should have searched for a solution before I spent the entire 3 minutes trying to figure it out.  But sometimes, I just like solving the puzzle.</p>
<blockquote></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/c-30/using-object-initializers-on-dictionary.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Preview 2 Released</title>
		<link>http://www.developingfor.net/c-30/aspnet-mvc-preview-2-released.html</link>
		<comments>http://www.developingfor.net/c-30/aspnet-mvc-preview-2-released.html#comments</comments>
		<pubDate>Thu, 06 Mar 2008 18:01:08 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/c-30/aspnet-mvc-preview-2-released.html</guid>
		<description><![CDATA[In another case of DGT (Darn Good Timing), in my inbox this morning was my copy of theToques 3320 baixar toques para celular Gratis, toques. Developer Fusion Community Newsletter, and the first item was this announcement. Being a very recent fan of the project, I immediately downloaded and installed the new Preview. Here are the [...]]]></description>
			<content:encoded><![CDATA[<p>In another case of DGT (Darn Good Timing), in my inbox this morning was my copy of the<noscript>Toques 3320 <a href="http://www.idealtoques.com/sites-baixar-toques-para-celular.html">baixar toques para celular</a> Gratis, toques.</noscript> Developer Fusion Community Newsletter, and the first item was this announcement. Being a very recent fan of the project, I immediately <a href="http://www.microsoft.com/downloads/details.aspx?familyid=38cc4cf1-773a-47e1-8125-ba3369bf54a3&amp;displaylang=en&amp;tm" title="ASP.NET MVC Preview 2" target="_blank">downloaded and installed the new Preview</a>. Here are the <a href="http://www.asp.net/downloads/3.5-extensions/readme/Preview2.aspx#_Toc192423261" title="ASP.NET MVC Release 2 Notes" target="_blank">Release Notes</a>. There are a few breaking changes, mostly object renames, but a little refactoring should take care of the bulk of it.</p>
<p>I spent some time yesterday playing around with it, and I am very happy with what I see. I plan to spend most of today reading Scott Guthrie&#8217;s excellent <a href="http://weblogs.asp.net/scottgu/archive/2008/02/12/asp-net-mvc-framework-road-map-update.aspx" title="Scott Guthrie" target="_blank">Tutorials</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/c-30/aspnet-mvc-preview-2-released.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC</title>
		<link>http://www.developingfor.net/net-35/aspnet-mvc.html</link>
		<comments>http://www.developingfor.net/net-35/aspnet-mvc.html#comments</comments>
		<pubDate>Wed, 05 Mar 2008 18:25:21 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/net-35/aspnet-mvc.html</guid>
		<description><![CDATA[As I posted previously, I&#8217;ve been struggling with ASP.NET. Over the last couple of weeks, I&#8217;ve come to acknowledge that at the heart of my struggles is a failure to grasp the logic behind the ASP.NET approach. Of course, begin constantly bitten by newbie bugs is very disheartening for someone with almost ten years of [...]]]></description>
			<content:encoded><![CDATA[<p>As I posted previously, I&#8217;ve been <a href="http://www.developingfor.net/c-30/trudging-through-aspnet.html" title="Trudging through ASP.NET">struggling with ASP.NET</a>. Over the last couple of weeks, I&#8217;ve come to acknowledge that at the heart of my struggles is a failure to grasp the logic behind the ASP.NET approach. Of course, begin constantly bitten by newbie bugs is very disheartening for someone with almost ten years of web development, but I have tried to put my pride aside and just come to grips with it. This has been increasingly difficult to do as my frustrations mount, although finding the Wizard control alleviated some of it.</p>
<p>I have been in the process of learning about Data Caching in ASP.NET, which I think will address one of my (many) concerns, but such study requires frequent breaks, during which I usually read some other technical information. It was during one of these breaks yesterday that I picked up the Jan/Feb issue of <a href="http://www.code-magazine.com/" title="CoDe Magazine" target="_blank"><em>CoDe: Component Developr Magazine</em></a>, and doing so may have saved my relationship with ASP.NET. In it, I came across an article by Jeffrey Palermo entitled &#8220;Use the ASP.NET MVC Framework to Write Web Apps without Viewstate or Postbacks&#8221; &#8211; <em>Note to Jeffrey: bloggers like short titles!</em> The two page article made me sit up and take notice, and I spent the rest of the day researching ASP.NET MVC. Championed by none other than Scott Guthrie (ScottGu to his readers), ASP.NET MVC is part of the ASP.NET 3.5 Extensions project hosted at <a href="http://asp.net" title="ASP.NET" target="_blank">asp.net</a>. This project was recently released as a CTP and is now available for download. You can get lots more information about it at <a href="http://weblogs.asp.net/scottgu/archive/2007/12/09/asp-net-3-5-extensions-ctp-preview-released.aspx" title="Scott Guthrie" target="_blank">Scott&#8217;s blog</a>.</p>
<p>By freeing ourselves from the mantra of the PostBack, this MVC approach returns us to real HTML control, without the need to wrap all the content in a runat=server form. This means you can finally put regular HTML forms on your pages. And best of all, you can still use all the ASP.NET goodies, just in a better architecture: Master Pages, ASP Controls, Code Behind, the works.</p>
<p>Downloading and installing the Extensions CTPwas a snap. Naturally, it integrates with VS2008, so once it is installed you will see some new project types, a couple of which are MVC specific. Selecting one of these project types will create a project with all the plumbing in place and wired, which I immediately found intuitive and well designed. There are several extra, but well documented, steps you must go through if you wish to add MVC to an existing project, but since I don&#8217;t really have any of consequence this was not an issue for me.</p>
<p>Hopefully, this afternoon I will find more time to delve into this further. I can say that I am very excited by this development. I can finally do things with ASP.NET that are familiar and comfortable. Projects like this could easily increase ASP.NET adoption and proliferation. My enthusiastic thanks go to all those involved!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/net-35/aspnet-mvc.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
