<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Marcelo's WebLog : Development</title><link>http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx</link><description>Tags: Development</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Mouse Gestures for Internet Explorer</title><link>http://blogs.msdn.com/marcelolr/archive/2009/12/18/mouse-gestures-for-internet-explorer.aspx</link><pubDate>Fri, 18 Dec 2009 22:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9938906</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9938906.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9938906</wfw:commentRss><description>&lt;P&gt;If there's something that I detest while working on my computer is having to switch between mouse and keyboard. Depending on what I'm doing, I'll typically have a keyboard-centric or mouse-centric approach.&lt;/P&gt;
&lt;P&gt;For example, coding is very much a keyboard-centric approach, and I very much dislike having to use the mouse for anything.&lt;/P&gt;
&lt;P&gt;Browsing, on the other hand, is largely a mouse-centric thing I do. I still haven't found anything that allows me to navigate links with the keyboard as effectively as I can with the mouse.&lt;/P&gt;
&lt;P&gt;Being a mouse-centric experience, all that I can do to keep using the mouse just makes things better. If you haven't checked out &lt;A href="http://ieaddons.com/en/details/other/Mouse_Gestures_for_Internet_Explorer/" mce_href="http://ieaddons.com/en/details/other/Mouse_Gestures_for_Internet_Explorer/"&gt;Mouse Gestures for Internet Explorer&lt;/A&gt;, that's a pretty nifty add-on. I haven't had problems with it so far, &lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Of course these opinions are mine and are not meant to represent those of my employer.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9938906" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category></item><item><title>Remember JScript closures capture all variables in scope</title><link>http://blogs.msdn.com/marcelolr/archive/2009/12/15/remember-jscript-closures-capture-all-variables-in-scope.aspx</link><pubDate>Tue, 15 Dec 2009 22:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9936792</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9936792.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9936792</wfw:commentRss><description>&lt;P&gt;Just a gentle reminder to readers, that different languages will capture outer variable with their own nuances, and sometimes these will make a difference.&lt;/P&gt;
&lt;P&gt;So, for example, C# will capture only what's needed in the inner function. See &lt;A href="http://srtsolutions.com/blogs/billwagner/archive/2008/01/22/looking-inside-c-closures.aspx" mce_href="http://srtsolutions.com/blogs/billwagner/archive/2008/01/22/looking-inside-c-closures.aspx"&gt;this post&lt;/A&gt; from Bill Wagner for a great discussion on the topic. Raymond Chen also covers this &lt;A href="http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx" mce_href="http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;One gotcha found in C# and VB.Net, for example, is that there is a &lt;A href="http://blogs.msdn.com/ericlippert/archive/2007/06/06/fyi-c-and-vb-closures-are-per-scope.aspx" mce_href="http://blogs.msdn.com/ericlippert/archive/2007/06/06/fyi-c-and-vb-closures-are-per-scope.aspx"&gt;single closure per scope&lt;/A&gt;, so if you have multiple functions capturing variables, they will all get the same scope.&lt;/P&gt;
&lt;P&gt;ECMAScript also has some gotchas. In particular, just declaring the inner function is enough for all variables in scope to be captured, regardless of whether they are ever used.&lt;/P&gt;
&lt;P&gt;You can try it right now in your address bar (yes, another &lt;A href="http://blogs.msdn.com/marcelolr/archive/2009/12/02/jscript-location-bar-silliness.aspx" mce_href="http://blogs.msdn.com/marcelolr/archive/2009/12/02/jscript-location-bar-silliness.aspx"&gt;silly&lt;/A&gt; &lt;A href="http://blogs.msdn.com/marcelolr/archive/2009/12/08/enumerate-window-elements.aspx" mce_href="http://blogs.msdn.com/marcelolr/archive/2009/12/08/enumerate-window-elements.aspx"&gt;trick&lt;/A&gt;).&lt;/P&gt;
&lt;P style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;javascript:(function(b){var a=1;var f=function(){alert(eval("a+b"));};f();})(2)&lt;/P&gt;
&lt;P&gt;Here is the formatted version of the code:&lt;/P&gt;
&lt;P style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;(function(b) {&lt;BR&gt;&amp;nbsp; var a=1;&lt;BR&gt;&amp;nbsp; var f=function() {&lt;BR&gt;&amp;nbsp;&amp;nbsp; alert(eval("a+b"));&lt;BR&gt;&amp;nbsp; };&lt;BR&gt;&amp;nbsp; f();&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;)(2)&lt;/P&gt;
&lt;P&gt;Running this will product a messagebox displaying '3'. So here we have a function that doesn't actually reference any variables directly, but they are still in scope because 'eval' can find them. Yes, parameters are included as well - they are function variables for all practical purposes.&lt;/P&gt;
&lt;P&gt;If you had other locals in the function, for example a large array, that wouldn't be collected until the inner function was out of scope for the program, and you'd have to remove the reference 'by hand' by setting it to null for example.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9936792" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Web/default.aspx">Web</category></item><item><title>Debugging Crash Dumps with Visual Studio 2010</title><link>http://blogs.msdn.com/marcelolr/archive/2009/12/07/debugging-crash-dumps-with-visual-studio-2010.aspx</link><pubDate>Mon, 07 Dec 2009 22:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9931720</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9931720.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9931720</wfw:commentRss><description>&lt;P&gt;If you're visually oriented, you &lt;STRONG&gt;need&lt;/STRONG&gt; to check out &lt;A href="http://channel9.msdn.com/posts/Glucose/Hanselminutes-on-9-Debugging-Crash-Dumps-with-Tess-Ferrandez-and-VS2010/" mce_href="http://channel9.msdn.com/posts/Glucose/Hanselminutes-on-9-Debugging-Crash-Dumps-with-Tess-Ferrandez-and-VS2010/"&gt;this video&lt;/A&gt;, with escalation engineer Tess Fernandez showing off some very nifty debugging features, including the ability to work with managed-code dump files and the "thread aggregating" stack views. See the whole thing, or jump to ~2:10 to get the dump, ~3:20 to open the dump, ~6:40 to view the parallel callstacks.&lt;/P&gt;
&lt;P&gt;For more on the parallel stacks view, &lt;A href="http://channel9.msdn.com/posts/DanielMoth/Parallel-Stacks--new-Visual-Studio-2010-debugger-window/" mce_href="http://channel9.msdn.com/posts/DanielMoth/Parallel-Stacks--new-Visual-Studio-2010-debugger-window/"&gt;this video&lt;/A&gt; is your friend.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9931720" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category></item><item><title>Microsoft Web Platform &amp; You</title><link>http://blogs.msdn.com/marcelolr/archive/2009/12/03/microsoft-web-platform-you.aspx</link><pubDate>Thu, 03 Dec 2009 22:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9931105</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9931105.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9931105</wfw:commentRss><description>&lt;P&gt;If you build web sites and applications, you owe it to yourself to check out the resources at &lt;A href="http://www.microsoft.com/web/"&gt;http://www.microsoft.com/web/&lt;/A&gt;&amp;nbsp;and to subscribe to the feed of the &lt;A href="http://blogs.msdn.com/webplatform/" mce_href="http://blogs.msdn.com/webplatform/"&gt;team blog&lt;/A&gt; to keep up to date with tools and capabilities. No reason to pass up on free software or to avoid leveraging the software you already have.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9931105" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Windows/default.aspx">Windows</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Web/default.aspx">Web</category></item><item><title>MSXML XHTML DTDs - making the web better</title><link>http://blogs.msdn.com/marcelolr/archive/2009/11/30/msxml-xhtml-dtds-making-the-web-better.aspx</link><pubDate>Mon, 30 Nov 2009 22:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9928868</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9928868.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9928868</wfw:commentRss><description>&lt;P&gt;The fix to requests for XHTML DTD files from the W3C Web server has been recently released. Windows Update should offer the fix automatically, but you can download and install the fix manually from the following links for various MSXML versions:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.microsoft.com/?kbid=973688"&gt;http://support.microsoft.com/?kbid=973688&lt;/A&gt; [MSXML4 SP2... if you haven't tried SP3 yet see below]&lt;BR&gt;&lt;A href="http://support.microsoft.com/?kbid=973685"&gt;http://support.microsoft.com/?kbid=973685&lt;/A&gt; [&lt;A href="http://blogs.msdn.com/xmlteam/archive/2009/03/06/msxml4-sp3-is-available-now.aspx" mce_href="http://blogs.msdn.com/xmlteam/archive/2009/03/06/msxml4-sp3-is-available-now.aspx"&gt;MSXML4 SP3&lt;/A&gt;]&lt;BR&gt;&lt;A href="http://support.microsoft.com/?kbid=973686"&gt;http://support.microsoft.com/?kbid=973686&lt;/A&gt; [MSXML6 Out-Of-Band, for XP SP2 and Win2K3]&lt;BR&gt;&lt;A href="http://support.microsoft.com/?kbid=973687"&gt;http://support.microsoft.com/?kbid=973687&lt;/A&gt; [MSXML3 and MSXML6 for all OSes where these components are in-band]&lt;/P&gt;
&lt;P&gt;What exactly is this about? Well, there are a number of cases where this can happen, but one common scenario that we've seen people run into when writing AJAX web pages is to request a page of information from the server, load it into an XML document and extract some information or merge it into the existing page.&lt;/P&gt;
&lt;P&gt;The problem with this approach is that when you load the document into an MSXML document "by hand" (ie, not through &lt;A href="http://msdn.microsoft.com/en-us/library/ms534370.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms534370.aspx"&gt;responseXML&lt;/A&gt; on the XHR object), DTD processing is enabled, and the DOCTYPE declaration directs MSXML to go look up the XHTML DTD so you can use entities like &amp;amp;nbsp;.&lt;/P&gt;
&lt;P&gt;Multiply this by each web browser accessing a popular site, and you can imagine why no-one is happy with this situation: web sites break when the resource is not available, the W3C servers get overloaded, and users of web sites lose functionality with odd scripting errors.&lt;/P&gt;
&lt;P&gt;The fix caches the XHTML DTDs in MSXML - these resources haven't changed for years and will likely end up in different URLs if something new comes along. So now clients save at least one round-trip (possibly more) and always get the DTD support they need.&lt;/P&gt;
&lt;P&gt;Try running this bit of script in a .js file to see the awesomeness in action.&lt;/P&gt;
&lt;P style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;function pullXHtml() {&lt;BR&gt;&amp;nbsp; var xml = new ActiveXObject("Msxml2.DOMDocument.3.0");&lt;BR&gt;&amp;nbsp; xml.async = false;&lt;BR&gt;&amp;nbsp; xml.loadXML(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"&amp;gt;" +&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;simple document&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;" +&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;body&amp;gt;&amp;lt;p&amp;gt;a simple&amp;amp;nbsp;paragraph&amp;lt;/p&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");&lt;BR&gt;&amp;nbsp; if (xml.parseError.errorCode != 0) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var myErr = xml.parseError;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.Echo("You have error " + myErr.reason);&lt;BR&gt;&amp;nbsp; } else {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.echo("Yay!");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WScript.echo(xml.xml);&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;pullXHtml();&lt;/P&gt;
&lt;P&gt;If you don't have the update, you might get an error such as the following.&lt;/P&gt;
&lt;P style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;You have error The server did not understand the request, or the request was invalid.&lt;BR&gt;Error processing resource 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'.&lt;/P&gt;
&lt;P&gt;If you do have the update, you'll see the parsed XML. Run this with &lt;A href="http://www.fiddler2.com/fiddler2/" mce_href="http://www.fiddler2.com/fiddler2/"&gt;Fiddler&lt;/A&gt; open and you'll&amp;nbsp;"see" the absence of network activity.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;BR&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9928868" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/XML/default.aspx">XML</category></item><item><title>Vistual Studio visualizer for OData</title><link>http://blogs.msdn.com/marcelolr/archive/2009/11/19/vistual-studio-visualizer-for-odata.aspx</link><pubDate>Thu, 19 Nov 2009 22:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9924569</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9924569.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9924569</wfw:commentRss><description>&lt;P&gt;Fabian Winternitz is one of our awesome tools developers, and you can see some of his work in &lt;A href="http://blogs.msdn.com/astoriateam/archive/2009/11/17/introducing-the-microsoft-open-data-protocol-visualizer.aspx" mce_href="http://blogs.msdn.com/astoriateam/archive/2009/11/17/introducing-the-microsoft-open-data-protocol-visualizer.aspx"&gt;this post&lt;/A&gt;. That's a Visual Studio extension that will display searchable diagrams for the model exposed by any service endpoint that exposes OData metadata. Which these days includes &lt;A href="http://blogs.msdn.com/astoriateam/archive/2009/11/17/breaking-down-data-silos-the-open-data-protocol-odata.aspx" mce_href="http://blogs.msdn.com/astoriateam/archive/2009/11/17/breaking-down-data-silos-the-open-data-protocol-odata.aspx"&gt;a lot of software&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Personally, I think it's great to see on one hand the level of support for the ecosystem, and on the other hand the balance of power, expressiveness and simplicity that OData provides. Back when everything started in the early days of Project "Astoria", I don't think anyone had any idea as to how broad a spectrum of software components would play in this space, but it looks like sticking to simplicity and proven standards paid off.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9924569" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category></item><item><title>XmlLite says: error C2146: syntax error : missing ';' before identifier 'IXmlReader'</title><link>http://blogs.msdn.com/marcelolr/archive/2009/06/05/xmllite-says-error-c2146-syntax-error-missing-before-identifier-ixmlreader.aspx</link><pubDate>Sat, 06 Jun 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9688013</guid><dc:creator>marcelolr</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9688013.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9688013</wfw:commentRss><description>&lt;P&gt;This is something that I've been asked more than once, and so here goes an answer that might help if you run into this.&lt;/P&gt;
&lt;P&gt;Let's say that you create a new project and borrow code or do something of the sort, and suddenly start getting an error message such as this one&lt;/P&gt;
&lt;P&gt;xmllite.h(49) : error C2146: syntax error : missing ';' before identifier 'IXmlReader'&lt;/P&gt;
&lt;P&gt;This typically points to a missing macro. You can fix this by adding this to your include headers:&lt;/P&gt;
&lt;P&gt;#include "objbase.h"&lt;/P&gt;
&lt;P&gt;If you're using Visual C++-style projects, this may already be included via stdafx.h including the Windows headers for you.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9688013" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/XML/default.aspx">XML</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Debugging and PDBs</title><link>http://blogs.msdn.com/marcelolr/archive/2009/05/12/debugging-and-pdbs.aspx</link><pubDate>Wed, 13 May 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9608011</guid><dc:creator>marcelolr</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9608011.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9608011</wfw:commentRss><description>&lt;P&gt;Debugging is hard. There are many things we do to make it easier on ourselves.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Feature-level things like building tracing and logging capabilities.&lt;/LI&gt;
&lt;LI&gt;Design-level things like having clear points at which state is checked for consistency (internal or parameters passed in, for example), so we narrow down the areas where things might have gone wrong.&lt;/LI&gt;
&lt;LI&gt;Code-level things like making sure that exceptions bubble up without losing the stack.&lt;/LI&gt;
&lt;LI&gt;Operational-level things like using tools to capture dumps on failure and monitoring performance counters, to have good data about the program and its environment.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;John Robbins has a great post about build-time and environment-setup-time things you can do to make your debugging life easier, and PDB files are a big part of it. If you haven't debugged symbol-indexed and source-indexed programs in the past, you're in for a treat.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/05/11/pdb-files-what-every-developer-must-know.aspx"&gt;http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/05/11/pdb-files-what-every-developer-must-know.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9608011" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Design/default.aspx">Design</category></item><item><title>Abstraction, simplicity and predictability</title><link>http://blogs.msdn.com/marcelolr/archive/2009/04/16/abstraction-simplicity-and-predictability.aspx</link><pubDate>Fri, 17 Apr 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9550067</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9550067.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9550067</wfw:commentRss><description>&lt;P&gt;As a short follow-up to my last post on &lt;A href="http://blogs.msdn.com/marcelolr/archive/2009/04/15/reasoning-about-code.aspx" mce_href="http://blogs.msdn.com/marcelolr/archive/2009/04/15/reasoning-about-code.aspx"&gt;reasoning about code&lt;/A&gt;, I wanted to touch upon &lt;STRONG&gt;abstraction in general&lt;/STRONG&gt; - meaning "information hiding" in the general sense, and not necessarily a particular programming mechanism such as polymorphism or some such thing.&lt;/P&gt;
&lt;P&gt;Abstraction buys us a number of good things for a design - the ability to think about things using fewer concepts (because we can focus on the more general stuff) and&amp;nbsp;the ability to change system behavior by changing an isolated part (the abstracted part), to name the first two that come to mind. In general, abstraction is a great way to have the consumer of the abstract &lt;STRONG&gt;focus&lt;/STRONG&gt; on something, by hiding or diverting focus away from the implementation particulars.&lt;/P&gt;
&lt;P&gt;There is a price to the use of abstraction, however. Well, there's more than a single thing in practice, but I want to focus on one. When you choose what to hide, you may run into the risk of making the system behavior &lt;STRONG&gt;harder to predict&lt;/STRONG&gt;, and as such more difficult to reason about.&lt;/P&gt;
&lt;P&gt;For example, if my abstraction doesn't explain some basics of the performance characteristics of the implementation, my only recourse is to profile to understand how the system will behave overall (you should profile anyway, but that's a separate matter). Or an abstraction might not give clear rules as to what happens when an object enters an error state - should you "not touch it", try to dispose of it, continue using it, or what?&lt;/P&gt;
&lt;P&gt;I'm not advocating any particular solutions or tradeoffs here, but instead I just want to bring awareness to the fact that &lt;STRONG&gt;there is a trade-off to be considered&lt;/STRONG&gt;. It's good to know how others will reason about our code, even if just to say "this isn't specified and you can't count on anything, so you should be careful and &lt;EM&gt;something&lt;/EM&gt;". Whether the "something" is 'ignore this', 'bail out', 'work around this', 'assume worst case', 'terminate the process', or something else, there should still be a clear way of explaining and reasoning about our code.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9550067" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Design/default.aspx">Design</category></item><item><title>Reasoning about code</title><link>http://blogs.msdn.com/marcelolr/archive/2009/04/15/reasoning-about-code.aspx</link><pubDate>Thu, 16 Apr 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9550056</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9550056.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9550056</wfw:commentRss><description>&lt;P&gt;When we have conversation about API design, or more generally about fragments of code that we write or we think customers will write, we often talk about &lt;STRONG&gt;reasoning about code&lt;/STRONG&gt;. We typically mean that someone reading the code will be able to understand the implications of making an API call for example, and write clean code accordingly. There is always a component of &lt;STRONG&gt;simplicity&lt;/STRONG&gt; in code someone can reason about.&lt;/P&gt;
&lt;P&gt;For example, someone might say that functional-style code is easier to reason about, because there are no side-effects and so you can concentrate on whatever local computation a given function does. Or someone might say that it's hard to reason about code that deals with an object that has entered an error state, because the results of operations are undefined and it's hard or impossible to keep track in your head about what the consequences of any given API call might be.&lt;/P&gt;
&lt;P&gt;I think that beyond simplicity, the core of &lt;EM&gt;code you can reason about&lt;/EM&gt; is &lt;STRONG&gt;predictability&lt;/STRONG&gt;. To the extent that you can predict the behavior of a fragment of code, and it's straightforward enough, you can reason about what the code does and what the impact of changes would be.&lt;/P&gt;
&lt;P&gt;Going back to the previous examples, functional-style code is easier to reason about because once you predict what it does locally, you understand the complete picture - there are no other, off-to-the-side effects. When an object is in an error state, you can't use it anymore ("you can't touch it", you might say) if you can't predict what it will do - the core of the problem is that you can no longer infer things about its behavior and put it together with other concepts to use it.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9550056" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Design/default.aspx">Design</category></item><item><title>Using partial methods to extend generated code</title><link>http://blogs.msdn.com/marcelolr/archive/2009/04/14/using-partial-methods-to-extend-generated-code.aspx</link><pubDate>Wed, 15 Apr 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9544015</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9544015.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9544015</wfw:commentRss><description>&lt;P&gt;To wrap up a bit on the &lt;A href="http://blogs.msdn.com/marcelolr/archive/2009/04/10/using-partial-classes-for-cleaner-more-maintainable-code.aspx" mce_href="http://blogs.msdn.com/marcelolr/archive/2009/04/10/using-partial-classes-for-cleaner-more-maintainable-code.aspx"&gt;partial class support for generated code scenario&lt;/A&gt;, let's look at a case we missed. Although our workflow is great for "structural" code (fields and simple properties and such), what about methods? For example, let's say that we want to add validation logic to a property setter.&lt;/P&gt;
&lt;P&gt;The problem we'll run into is that the property setter has already been defined in the generated file, and there's no way to extend this directly. Well, we can always add code to the generated file, but we're back to square one with the problem of having our changes overwritten if the code is re-generated.&lt;/P&gt;
&lt;P&gt;The solution C# offers is the use of &lt;A href="http://msdn.microsoft.com/en-us/library/wa80x488.aspx" mce_href="http://msdn.microsoft.com/en-us/library/wa80x488.aspx"&gt;partial methods&lt;/A&gt;. Partial methods can be declared more than once, but must have a body only in&amp;nbsp;at most a single file. The interesting thing is that it's OK for a partial method to have no body it all, in which case the compiler can simply ignore the method everywhere - no calls will be made, and the method itself won't exist in the assembly.&lt;/P&gt;
&lt;P&gt;For example, we can have a &lt;EM&gt;FirstNameChanged&lt;/EM&gt; method that takes in the new value of the property declared in the code-generate file, and called by the &lt;EM&gt;FirstName&lt;/EM&gt; property setter. If we choose to supply an implementation for the method in another file, we'll get called&amp;nbsp;- otherwise, nothing happens.&lt;/P&gt;
&lt;P&gt;Note that there are restrictions as to what the signature of a method may look like - in general, you can't depend on values being returned directly or through &lt;EM&gt;out&lt;/EM&gt; parameters, but modifying things through &lt;EM&gt;ref&lt;/EM&gt; parameters (or mutable parameters) is OK.&lt;/P&gt;
&lt;P&gt;For example, let's say I have a file with this code.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;namespace&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; CsNamespace&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;using&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; System;&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;using&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; System.Text;&lt;BR&gt;&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Cs&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SayHello();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SayHelloHere(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;StringBuilder&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; builder);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Main(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;[] args)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cs cs = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Cs();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Console&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Invoking SayHello..."&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cs.SayHello();&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;StringBuilder&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; sb = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;StringBuilder&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Console&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Invoking SayHelloHere..."&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cs.SayHelloHere(sb);&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; (sb.Length == 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Console&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Nothing happened."&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Console&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Something happened!"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Console&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(sb.ToString());&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; &amp;nbsp; }&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;P&gt;Now, if I compile it on its own, this is the output I get.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;Invoking SayHello...&lt;BR&gt;Invoking SayHelloHere...&lt;BR&gt;Nothing happened.&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;However I can go ahead and add an additional file to the project.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;namespace&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; CsNamespace&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;using&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; System;&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;using&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; System.Text;&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp; public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Cs&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SayHello()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Console&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Hello"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SayHelloHere(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;StringBuilder&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; builder)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.AppendLine(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Hello"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT size=2&gt;}&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;P&gt;Now, if I compile both files and run, this is the output I get.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;Invoking SayHello...&lt;BR&gt;Hello&lt;BR&gt;Invoking SayHelloHere...&lt;BR&gt;Something happened!&lt;BR&gt;Hello&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;As you can see, all the partial calls were now made into the implementation I defined in the extra file.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9544015" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category></item><item><title>Using partial classes with nested classes for maintainability</title><link>http://blogs.msdn.com/marcelolr/archive/2009/04/13/using-partial-classes-with-nested-classes-for-maintainability.aspx</link><pubDate>Tue, 14 Apr 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9543956</guid><dc:creator>marcelolr</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9543956.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9543956</wfw:commentRss><description>&lt;P&gt;C# allows you to create &lt;A href="http://msdn.microsoft.com/en-us/library/ms173120.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms173120.aspx"&gt;nested classes&lt;/A&gt; - that is, classes that exist "within" a different class. Depending on what visibility you give these classes, they can be just as public as anything else (the &lt;A href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx"&gt;Environment.SpecialFolder&lt;/A&gt; enumeration is such an example). If you use 'internal', other classes in the assembly will be able to see it, but not classes in other assemblies.&lt;/P&gt;
&lt;P&gt;The special thing about nested classes is that you can declare them as &lt;EM&gt;private&lt;/EM&gt; (the default), in which case only the containing type gets to access the class. This allows for a more controlled usage of the class, and is great for helper classes that should only be used by a single class.&lt;/P&gt;
&lt;P&gt;One of the problems you may run into when using nested types is that if they have any reasonable size at all, it's likely that the file in which they're used ends up looking very odd - you usually end up with a much bigger file than in the rest of your project, and when you're on a method it may be difficult to tell which class the method is in. In a way, it breaks down the good advise of not having many classes in a single file.&lt;/P&gt;
&lt;P&gt;Can you have your cake and eat it too? Of course (this would be a poor blog post otherwise I guess). &lt;A href="http://blogs.msdn.com/marcelolr/archive/2009/04/10/using-partial-classes-for-cleaner-more-maintainable-code.aspx" mce_href="http://blogs.msdn.com/marcelolr/archive/2009/04/10/using-partial-classes-for-cleaner-more-maintainable-code.aspx"&gt;Partial classes&lt;/A&gt; come to the rescue again. In this case we're not using them to be able to separate tool-generated from "us-"generated code, instead we're using them to separate a nested class into its own file.&lt;/P&gt;
&lt;P&gt;To work on the previous example, let's say&amp;nbsp;I have a file that declare a class Cs and uses a nested class NestedClass.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;namespace&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; CsNamespace&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Cs&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Main(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;[] args)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;// Here we can also refer to Cs.NestedClass as 'NestedClass'.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;NestedClass instance = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Cs.NestedClass();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; instance.FirstName = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Marcelo"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; instance.LastName = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Lopez Ruiz"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Console&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(instance.FullName);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;P&gt;Now I can include this in a separate file and compile both of them together in the same project. Note that the class I've marked as &lt;EM&gt;partial&lt;/EM&gt; is Cs - in this example, I have no need to mark NestedClass as &lt;EM&gt;partial&lt;/EM&gt;, as its complete definition can be found in this single file.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;namespace&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; CsNamespace&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Cs&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;private&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;NestedClass&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; FirstName { &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;get&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; LastName { &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;get&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; FullName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;get&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; { &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;return&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.FirstName + &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;" "&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; + &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.LastName; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;P&gt;Other classes in the project will now need to "behave", and they can't break the encapsulation provided by the private nested class.&lt;/P&gt;&lt;FONT size=2&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;AnotherClass&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Foo()&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;// Uncommenting this gives error, for example:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;//&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;// error CS0122: 'CsNamespace.Cs.NestedClass' is &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;// inaccessible due to its protection level&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;//&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;// Cs.NestedClass instance = new Cs.NestedClass();&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;}&lt;BR&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9543956" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category></item><item><title>Using partial classes for cleaner, more maintainable code</title><link>http://blogs.msdn.com/marcelolr/archive/2009/04/10/using-partial-classes-for-cleaner-more-maintainable-code.aspx</link><pubDate>Sat, 11 Apr 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9543921</guid><dc:creator>marcelolr</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9543921.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9543921</wfw:commentRss><description>&lt;P&gt;Frequently you'll write classes that represent a concept that is also described elsewhere. For example, you'll have a class that represent a row in a table, a service the web or the graphical design of a form. These external concepts have descriptions which can be consumed by machines, for example through SQL metadata queries or through XML descriptions of structure or services.&lt;/P&gt;
&lt;P&gt;It's often handy to generate the code from these descriptions. For example, I can query a database to find out the columns a table has, and then create a class with one field per column. I can then create instances of this class to represent and manipulate rows. Handy-dandy, except that now I run into a problem when I want to re-run this code generate process: if I overwrite the existing files, I'll lose whatever changes I made by hand since the last generation.&lt;/P&gt;
&lt;P&gt;C# has a nice feature that helps with this: partial classes. When you add the &lt;EM&gt;partial&lt;/EM&gt; keyword to a class, you're telling the compiler "there might be additional things defined for this class in another file". Note that you can't use &lt;EM&gt;partial&lt;/EM&gt; to split code between assemblies or anything funny - it's just compiler magic, and at the end of the day it's a lot like copy-pasting the contents from one file inside another.&lt;/P&gt;
&lt;P&gt;Let's see an example. Let's say I have a file cs1.cs, which contains structure that I mapped from somewhere, perhaps a table in a database or some known arrangements of keys in the registry.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;namespace&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; CsNamespace&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Cs&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; FirstName { &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;get&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; LastName { &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;get&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;; }&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P&gt;Now, let's say that I want to also add a "calculated field" to this, FullName. And while I'm at it, I also want to turn this class into an assembly entry point, so I can just compile the class and have a program. I can write the following file and save it as cs2.cs.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;namespace&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; CsNamespace&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;partial&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Cs&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; FullName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT size=2&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;get&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; { &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;return&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.FirstName + &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;" "&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; + &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.LastName; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;BR&gt;&amp;nbsp; &amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Main(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;[] args)&lt;BR&gt;&amp;nbsp; &amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cs instance = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Cs();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; instance.FirstName = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Marcelo"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; instance.LastName = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Lopez Ruiz"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Console&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(instance.FullName);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P&gt;This will now work just fine when compiled together.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;&amp;gt; csc.exe /out:cs.exe cs1.cs cs2.cs&lt;BR&gt;...&lt;BR&gt;&amp;gt; cs.exe&lt;BR&gt;Marcelo Lopez Ruiz&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;You can read more on &lt;A href="http://msdn.microsoft.com/en-us/library/wa80x488.aspx" mce_href="http://msdn.microsoft.com/en-us/library/wa80x488.aspx"&gt;partial classes on MSDN&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9543921" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category></item><item><title>GetCurrentMethod and lambdas - watch out</title><link>http://blogs.msdn.com/marcelolr/archive/2009/03/31/getcurrentmethod-and-lambdas-watch-out.aspx</link><pubDate>Wed, 01 Apr 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9523022</guid><dc:creator>marcelolr</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9523022.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9523022</wfw:commentRss><description>&lt;P&gt;Got bit by this a few moments ago... Thankfully it didn't take long, but probably because this was fairly isolated in my case; I could imagine getting stuck for a bit longer if this were a larger piece of code.&lt;/P&gt;
&lt;P&gt;Anyway, I was running method that&amp;nbsp;goes through a&amp;nbsp;array and looks for a reference to the method itself, using &lt;A href="http://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getcurrentmethod.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getcurrentmethod.aspx"&gt;MethodBase.GetCurrentMethod&lt;/A&gt;. I had the following code.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; AnInterestingMethod()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;var&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; result = &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Thingy&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.ListInterestingMethods(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.GetType().Assembly);&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Assert&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.IsTrue(result.Any(method =&amp;gt; method == &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;MethodBase&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.GetCurrentMethod()));&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;...&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT size=2&gt;And yet I wasn't finding a match. After looking at this for a bit, I realized that of course the &lt;EM&gt;GetCurrentMethod&lt;/EM&gt; call won't execute in this method, but in the lambda, with its own &lt;A href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb397687.aspx"&gt;anonymous function&lt;/A&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The following rewrite shows finds the method as expected.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Consolas, Lucida Console, Courier New"&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; AnInterestingMethod()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;var&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; result = &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Thingy&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.ListInterestingMethods(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.GetType().Assembly);&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;MethodBase&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; m = &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;MethodBase&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.GetCurrentMethod();&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Assert&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.IsTrue(result.Any(method =&amp;gt; method == m));&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;...&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Now the &lt;EM&gt;GetCurrentMethod&lt;/EM&gt; call executes in the interesting method itself, which of course makes it show up in the list.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9523022" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category></item><item><title>Velocity at DevConnections</title><link>http://blogs.msdn.com/marcelolr/archive/2009/03/20/velocity-at-devconnections.aspx</link><pubDate>Sat, 21 Mar 2009 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9491839</guid><dc:creator>marcelolr</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/marcelolr/comments/9491839.aspx</comments><wfw:commentRss>http://blogs.msdn.com/marcelolr/commentrss.aspx?PostID=9491839</wfw:commentRss><description>&lt;P&gt;Next Monday I'll be at &lt;A href="http://www.devconnections.com/" mce_href="http://www.devconnections.com/"&gt;DevConnections&lt;/A&gt; in Orlando, talking about &lt;A href="http://msdn.microsoft.com/en-us/data/cc655792.aspx" mce_href="http://msdn.microsoft.com/en-us/data/cc655792.aspx"&gt;Velocity&lt;/A&gt; (Microsoft Project Code Named "Velocity", if you like formality).&lt;/P&gt;
&lt;P&gt;It's going to be a bit of a challenge to sum up all that awesomeness into a single session, but I promise I'll do my best, and I'll be around for the rest of the event in case anyone wants to get in touch. Contact through email and blog will be slow, but should get back in rhythm after the event.&lt;/P&gt;
&lt;P&gt;In case you find the online list a tad long to search through, the session is titled an unsurprising &lt;EM&gt;MDA02: Microsoft Project Codenamed Velocity: A Distributed In-memory Cache&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;See you in Orlando!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9491839" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/marcelolr/archive/tags/Velocity/default.aspx">Velocity</category></item></channel></rss>