<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.microsoft.co.il/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>Pavel&amp;#39;s Blog</title><link>http://blogs.microsoft.co.il/blogs/pavely/</link><description>&lt;h4&gt;Pavel is a software guy that is interested in almost everything&lt;br /&gt;
software related... way too much for too little time&lt;/h4&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Color Gradient Generator</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/11/12/color-gradient-generator.aspx</link><pubDate>Tue, 12 Nov 2013 20:49:51 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2870708</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2870708</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2870708</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/11/12/color-gradient-generator.aspx#comments</comments><description>&lt;p&gt;A while back, I created a WPF &lt;a href="http://en.wikipedia.org/wiki/Mandelbrot_set" target="_blank"&gt;Mandelbrot Set&lt;/a&gt; program with zoom abilities. I demonstrated the use of &lt;a href="http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx" target="_blank"&gt;async/await&lt;/a&gt; for writing code that works asynchronously (to keep the UI responsive), but is easy to write as synchronous code. Here’s a sample image:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_58B1CD0D.png"&gt;&lt;img width="448" height="448" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_37A3302E.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The image is grayscale, so I wanted to make it use colors, to indicate the level of “being part of” the Mandelbrot set. The problem here is how to create a nice color gradient that moves smoothly from color to color.&lt;/p&gt;&lt;p&gt;One possible option might be to leverage an existing class, such as WPF’s &lt;a href="http://msdn.microsoft.com/EN-US/library/ms635198(v=VS.110,d=hv.2).aspx" target="_blank"&gt;LinearGradientBrush&lt;/a&gt;, set up a bunch of gradient stops with the colors to be interpolated, and then extract a color in a specific offset as needed. There are two issues with this: the first is that &lt;strong&gt;LinearGradientBrush&lt;/strong&gt; has no method to get the color at a specified offset, and second, I would rather create a generic algorithm that did not depend on a particular technology.&lt;/p&gt;&lt;p&gt;My goal would be to create a color gradient of some kind and apply it to the Mandelbrot set to get images such as the following:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_1EF0B693.png"&gt;&lt;img width="450" height="391" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_354FDCF5.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_3F85D71D.png"&gt;&lt;img width="457" height="397" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_4374FAB7.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_43573FCE.png"&gt;&lt;img width="459" height="398" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_6F0EFA36.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_14E98055.png"&gt;&lt;img width="462" height="401" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_7B886D86.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;There are several ways to do this, here I’ll describe one that works for me, and is not too complex to understand and implement.&lt;/p&gt;&lt;p&gt;The idea is to change the color based on a sine wave. This gives a nice smooth gradient effect (although it’s not linear, which is not a requirement anyway). By changing the frequency of the RGB components (we could theoretically work with other color spaces such as HSV) we can get various gradients. Also, we can also play with the phase of each color component, creating a “shifting” effect. The basic implementation of such a gradient can be implemented like so:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6cf8d174-c465-4070-a914-d896a7ff2c9a" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;Color&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;[] GenerateColors(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; number) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; colors = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;List&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;Color&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt;(number);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;double&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; step = MaxAngle / number;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;for&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; i = 0; i &amp;lt; number; ++i) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; r = (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;Math&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Sin(FreqRed * i * step + PhaseRed) + 1) * .5;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; g = (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;Math&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Sin(FreqGreen * i * step + PhaseGreen) + 1) * .5;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; b = (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;Math&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Sin(FreqBlue * i * step + PhaseBlue) + 1) * .5;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;colors.Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;Color&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.FromRgb((&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;byte&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)(r * 255), (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;byte&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)(g * 255), (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;byte&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)(b * 255)));&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; colors.ToArray();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;Where the &lt;strong&gt;Freq*&lt;/strong&gt; are the frequencies of the respective RGB colors and&lt;strong&gt; Phase*&lt;/strong&gt; are the phase shift values. Note that all calculations are done with floating point numbers (ranging from 0.0 to 1.0), converting to a WPF &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color.aspx" target="_blank"&gt;Color&lt;/a&gt; structure (in this case) at the very end. This is simply convenient, as we’re working with trigonometric functions, which like floating point numbers rather than integers. The result is normalized to the range 0 to 1, as the sine function produces results from –1 to 1, so we add one to get a range of 0 to 2 and finally divide by 2 to get to the desired range.&lt;/p&gt;&lt;p&gt;To create nice gradients, a lot of trial and error is needed. To make things easier, I created a helper program that allows changing the aforementioned properties using sliders, getting an immediate feedback of the result. I also added an option to export the selected values to an XML file and vice versa for importing. Here are some screenshots of the tool:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_77EEB264.png"&gt;&lt;img width="543" height="242" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_0EFC71FA.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_52249DCF.png"&gt;&lt;img width="541" height="306" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_11D0C96C.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The &lt;strong&gt;Size&lt;/strong&gt; slider sets the number of color entries in the returned array, and the &lt;strong&gt;MaxAngle&lt;/strong&gt; parameter effectively sets the number of sine cycles to use; or put another way, the rate in which the gradient changes.&lt;/p&gt;&lt;p&gt;The color gradient generator and the color based Mandelbrot set can be downloaded from the following link:&lt;/p&gt;&lt;p&gt;&lt;a href="http://sdrv.ms/HLlVG9" target="_blank"&gt;Async Mandelbrot Color&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2870708" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Fun/default.aspx">Fun</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Numerics/default.aspx">Numerics</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_+5.0/default.aspx">C# 5.0</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET+4.5/default.aspx">.NET 4.5</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Algorithms/default.aspx">Algorithms</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio+2012/default.aspx">Visual Studio 2012</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio+2013/default.aspx">Visual Studio 2013</category></item><item><title>MVVM View vs. Control</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/11/03/mvvm-view-vs-control.aspx</link><pubDate>Sun, 03 Nov 2013 12:41:55 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2807082</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2807082</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2807082</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/11/03/mvvm-view-vs-control.aspx#comments</comments><description>&lt;p&gt;In the MVVM world, Views are attached to ViewModels. How can a view be implemented? Typical answers for say, WPF, are: &lt;a href="http://msdn.microsoft.com/EN-US/library/ms590112(v=VS.110,d=hv.2).aspx" target="_blank"&gt;Window&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.usercontrol(v=vs.110).aspx" target="_blank"&gt;User Control&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.aspx" target="_blank"&gt;Data Template&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;. Similar answers exist for Windows Phone and Windows 8, where “Window” may be dropped or replaced by &lt;strong&gt;Page&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;This is certainly true, but about that User Control? Can any user control automatically be considered a View? Not quite.&lt;/p&gt;&lt;p&gt;The distinction between view and control (user control or otherwise) is based on reusability and dependency. A View requires a ViewModel to give it context. A View cannot function without a ViewModel. Typical XAML View would hook up to properties exposed by the ViewModel like the following:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&amp;lt;TextBox Text=”{Binding ItemName, Mode=TwoWay}” /&amp;gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;The lack of &lt;strong&gt;Source&lt;/strong&gt; or &lt;strong&gt;ElementName&lt;/strong&gt; in the binding indicates that the source is the closest &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.datacontext(v=vs.110).aspx" target="_blank"&gt;DataContext&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;, which is typically the ViewModel instance attached to the View.&lt;/p&gt;&lt;p&gt;The View is completely dependent on that ViewModel for data (and possibly commands to invoke), and is not intended to be reused in other applications. This is regardless of the actual implementation object, whether that is a Window, User Control or Data Template.&lt;/p&gt;&lt;p&gt;A User Control, on the other hand, when built as a control (and not a view) is independent and hopefully reusable. If it has any binding expressions in its XAML, they bind to its own properties, which of course are meant to be set by the control’s client. Such a control can typically be reused in many apps. A View may, for instance, use the Control as part of its user interface.&lt;/p&gt;&lt;p&gt;Here’s a simple example: login control/view.&lt;/p&gt;&lt;p&gt;Such a control, when built as a view would have a &lt;strong&gt;TextBox&lt;/strong&gt; for username, similar to the following:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&amp;lt;TextBox Text=”{Binding UserName, Mode=TwoWay}” … /&amp;gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;When built as a control, that same TextBox would have markup similar to the following:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&amp;lt;TextBox Text=”{Binding UserName, ElementName=This, Mode=TwoWay}” … /&amp;gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Assuming “This” is the &lt;strong&gt;x:Name&lt;/strong&gt; of the User Control itself (not an external name), and &lt;strong&gt;UserName&lt;/strong&gt; is a dependency property that the control exposes.&lt;/p&gt;&lt;p&gt;For the latter case, a Login View would be able to use the Login User Control as part of its UI, perhaps adding a “Forgot password” button to the UI. The aforementioned username would be hooked up as follows:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&amp;lt;mycontrols:LoginControl UserName=”{Binding UserName, Mode=TwoWay}” … /&amp;gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Where the second &lt;strong&gt;UserName&lt;/strong&gt; is a property of the ViewModel; in this simple case, with the same name as the property of the login control itself; this is certainly not necessary.&lt;/p&gt;&lt;p&gt;To summarize, a true control is independent of any ViewModel, and is built as such for maximum reusability. A View is much more specific, serving the purpose of a particular application, where reusability is not necessary nor needed; it’s tuned to the specific app’s requirements.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2807082" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+Phone/default.aspx">Windows Phone</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/MVVM/default.aspx">MVVM</category></item><item><title>Using KeyedCollection&lt;&gt; instead of a Dictionary&lt;&gt;</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/10/23/using-keyedcollection-lt-gt-instead-of-a-dictionary-lt-gt.aspx</link><pubDate>Wed, 23 Oct 2013 14:00:35 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2757172</guid><dc:creator>pavely</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2757172</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2757172</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/10/23/using-keyedcollection-lt-gt-instead-of-a-dictionary-lt-gt.aspx#comments</comments><description>&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx" target="_blank"&gt;System.Collections.Generic.Dictionary&amp;lt;TKey, TValue&amp;gt;&lt;/a&gt; class is one of the most useful of all .NET collections. It maps a key to a value, and allows for fast retrieval based on the key, as it’s implemented as a hash table, calling &lt;a href="http://msdn.microsoft.com/en-us/library/system.object.gethashcode(v=vs.110).aspx" target="_blank"&gt;GetHashCode&lt;/a&gt; on the key object to get to a specific “bucket”, and then looks up the actual value (with &lt;a href="http://msdn.microsoft.com/en-us/library/bsc2ak47(v=vs.110).aspx" target="_blank"&gt;Object.Equals&lt;/a&gt; or a specific &lt;a href="http://msdn.microsoft.com/en-us/library/ms132151.aspx" target="_blank"&gt;IEqualityComparer&amp;lt;Tkey&amp;gt;&lt;/a&gt;.&lt;a href="http://msdn.microsoft.com/en-us/library/ms132154.aspx" target="_blank"&gt;Equals&lt;/a&gt;).&lt;/p&gt;&lt;p&gt;One feature that &lt;strong&gt;Dictionary&amp;lt;&amp;gt;&lt;/strong&gt; doesn’t support is the ability to access items by integer index. That is, insertion order is not maintained. For most cases, this may be ok, but some cases require fast search and index based access.&lt;/p&gt;&lt;p&gt;Some values contain the keys themselves. Here’s a simple &lt;strong&gt;Customer&lt;/strong&gt; class:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:784fc142-c5ea-486c-9fd6-18116142a545" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Id { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Name { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Address { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;Let’s suppose that the &lt;strong&gt;Id&lt;/strong&gt; of a &lt;strong&gt;Customer&lt;/strong&gt; is unique, and so can serve as a key. Here’s a dictionary of such customers:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f4a8b7e0-582e-4a43-bb84-a8c3ec0a4b87" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; customers = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Dictionary&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;customers.Add(1, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; { Id = 1, Name = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;Bart Simpson&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; });&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;customers.Add(20, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; { Id = 20, Name = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;Homer Simpson&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; });&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;This seems harmless enough, but notice that the key (Id) is supplied twice. This may not seem like a big deal, but the key could be a more complex entity. It’s also not as elegant as we would like. I’d rather just use code like the following:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0e6b9a6c-3d61-45c4-bb37-660e77fa2349" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;customers.Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; { Id = 1, Name = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;Bart Simpson&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; });&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;And get the same result, that is, the &lt;strong&gt;Id&lt;/strong&gt; is still a key to search by. Dictionary&amp;lt;&amp;gt; cannot take that syntax. Enter &lt;a href="http://msdn.microsoft.com/EN-US/library/ms132438(v=VS.110,d=hv.2).aspx" target="_blank"&gt;KeyedCollection&amp;lt;&amp;gt;.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;KeyedCollection&amp;lt;TKey, TValue&amp;gt;&lt;/strong&gt; is an abstract base class that inherits from &lt;a href="http://msdn.microsoft.com/en-us/library/ms132397.aspx" target="_blank"&gt;Collection&amp;lt;TValue&amp;gt;&lt;/a&gt;, thus giving it index-based access. A requirement is that the key is somewhere inside the value, or connected to the value, as is the case with our &lt;strong&gt;Customer&lt;/strong&gt; class. The only question remains is how to return a key based on a value?&lt;/p&gt;&lt;p&gt;This is why we need a new class, extending &lt;strong&gt;KeyedCollection&amp;lt;&amp;gt;&lt;/strong&gt; and overriding a single abstract method, &lt;a href="http://msdn.microsoft.com/en-us/library/ms132454.aspx" target="_blank"&gt;GetKeyForItem&lt;/a&gt;:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:34818bb3-b938-4198-b5a5-ddeaea0a413b" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;CustomerCollection&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; : &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;KeyedCollection&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt; {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; GetKeyForItem(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; item) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; item.Id;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;This says that given a &lt;strong&gt;Customer&lt;/strong&gt;, its key is its &lt;strong&gt;Id&lt;/strong&gt;. Now we can use this class as follows:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e38cdcf3-22f8-47f1-8862-0c6e7958c4e6" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; customers = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;CustomerCollection&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;customers.Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; { Id = 1, Name = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;Bart Simpson&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; });&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;customers.Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; { Id = 20, Name = &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;Homer Simpson&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; });&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;We just add &lt;strong&gt;Customer&lt;/strong&gt; objects, and internally they are keyed by Id. The &lt;strong&gt;Add&lt;/strong&gt; method used is the one from &lt;strong&gt;Collection&amp;lt;TValue&amp;gt;&lt;/strong&gt;. This means, we can also access customers by index, or search using the &lt;a href="http://msdn.microsoft.com/en-us/library/ms132452(v=vs.110).aspx" target="_blank"&gt;Contains&lt;/a&gt; method.&lt;/p&gt;&lt;p&gt;As an extra bonus, the &lt;strong&gt;KeyedCollection&amp;lt;&amp;gt;&lt;/strong&gt; can be configured to &lt;strong&gt;not&lt;/strong&gt; create an internal Dictionary&amp;lt;&amp;gt;, depending on the number of items. For a small number of items, Dictionary&amp;lt;&amp;gt; is an overkill, and a linear search is faster. By default, a Dictionary is created upon first insertion, but this can be configured by using one of KeyedCollection&amp;lt;&amp;gt;’s constructors.&lt;/p&gt;&lt;p&gt;The idea of mapping a value to a key as was done in &lt;strong&gt;GetKeyForItem&lt;/strong&gt; can be generalized, so that we don’t have to create new classes for new types. Here’s a generalized class that uses a delegate to execute the required code in &lt;strong&gt;GetKeyForItem&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:731bb2b8-f9c7-4c98-8253-6fe453c99fef" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;[&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Serializable&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;]&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;sealed&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;GenericKeyedCollection&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;TKey, TValue&amp;gt; : &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;KeyedCollection&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;TKey, TValue&amp;gt; {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Func&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;TValue, TKey&amp;gt; _itemKey;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; GenericKeyedCollection(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Func&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;TValue, TKey&amp;gt; itemKey, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;IEqualityComparer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;TKey&amp;gt; comparer = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; threshold = 0)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;base&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(comparer, threshold) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(itemKey == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;throw&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ArgumentNullException&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;itemKey&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;_itemKey = itemKey;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; TKey GetKeyForItem(TValue item) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; _itemKey(item);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;With this class in hand, we can create a &lt;strong&gt;Customer&lt;/strong&gt; collection like so:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f368733f-d05e-42bb-a3f0-d153a63933f6" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; customers = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;GenericKeyedCollection&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Customer&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt;(c =&amp;gt; c.Id);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;Pretty neat.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2757172" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category></item><item><title>Tip: Turning Win32 Console app to non-Console app</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/09/30/tip-turning-win32-console-app-to-non-console-app.aspx</link><pubDate>Mon, 30 Sep 2013 18:51:20 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2658590</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2658590</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2658590</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/09/30/tip-turning-win32-console-app-to-non-console-app.aspx#comments</comments><description>&lt;p&gt;Let’s say you’ve created a &lt;strong&gt;Win32 Console Application&lt;/strong&gt; in Visual Studio:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_4F4D002B.png"&gt;&lt;img width="471" height="366" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_1E2F9495.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;We get the classic main function.&lt;/p&gt;&lt;p&gt;Now suppose that after working on the project for a while we want to turn the app into a Windows app – no console. At first, this seems easy: just replace the main function with a proper &lt;strong&gt;WinMain&lt;/strong&gt;:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:848b328d-23fe-4031-9530-66a293f56d24" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;_tWinMain&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;HINSTANCE&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;hInstance&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;HINSTANCE&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;LPTSTR&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;lpCmdLine&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;nCmdShow&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;Unfortunately, that’s not enough. Building the project produces the following linker error:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;The linker still expects a &lt;strong&gt;main&lt;/strong&gt; function.&lt;/p&gt;&lt;p&gt;The solution is (apart from creating a new project, adding the files, making any changes to the project again) is to switch the subsystem by using the &lt;strong&gt;Linker&lt;/strong&gt; / &lt;strong&gt;System&lt;/strong&gt; property tab and changing &lt;strong&gt;SubSystem &lt;/strong&gt;to &lt;strong&gt;Windows &lt;/strong&gt;(instead of &lt;strong&gt;Console&lt;/strong&gt;):&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_36A407AD.png"&gt;&lt;img width="471" height="335" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_2A5FB13B.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;And voila! The project links successfully.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2658590" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+C_2B002B00_/default.aspx">Visual C++</category></item><item><title>Getting rid of the Start button – Adding a Hook</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/09/16/getting-rid-of-the-start-button-adding-a-hook.aspx</link><pubDate>Mon, 16 Sep 2013 19:42:29 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2608456</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2608456</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2608456</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/09/16/getting-rid-of-the-start-button-adding-a-hook.aspx#comments</comments><description>&lt;p&gt;In the &lt;a href="http://blogs.microsoft.co.il/blogs/pavely/archive/2013/09/15/getting-rid-of-the-start-button-in-windows-8-1.aspx" target="_blank"&gt;previous post&lt;/a&gt; we saw how to find and remove the start button and move the task bar window to the left to occupy the free space left by the former start button.&lt;/p&gt;&lt;p&gt;However, we saw that by opening the system tray, the task bar moves back to its original position. We need to know when that happens, and then use the same trick to move it back to the “right” position.&lt;/p&gt;&lt;p&gt;To do that we would need to register somehow for the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632631(v=vs.85).aspx" target="_blank"&gt;WM_MOVE&lt;/a&gt; message. This is one option, and we can verify this using Spy++’s &lt;strong&gt;Message&lt;/strong&gt; window for task bar (again, another exercise for the reader).&lt;/p&gt;&lt;p&gt;The problem is that in Windows, a window message is posted or sent to the thread that created the window. Since the task bar was created by some thread in &lt;strong&gt;Explorer.Exe&lt;/strong&gt;, clearly we can’t just expect that message to arrive at our doorstep. For that, we need a hook.&lt;/p&gt;&lt;p&gt;The term “hook” signifies some kind of interception mechanism, and indeed this is its meaning in this case. We want to know when the task bar’s creator thread receives such a message and act accordingly. &lt;/p&gt;&lt;p&gt;This kind of hook is supported by the Windows subsystem through the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx" target="_blank"&gt;SetWindowsHookEx&lt;/a&gt; API function. It allows (among other things) to look at messages targeted at a particular thread (what we need) or even every thread on the current desktop (which may be useful for system-wide, or at least desktop-wide, hooking).&lt;/p&gt;&lt;p&gt;Before we call this function, we need to prepare a few things. The first and most important thing is to create a DLL. This is necessary, as our hook function is called in the context of the thread that created that window, which means it’s running under an &lt;strong&gt;Explorer.Exe&lt;/strong&gt; process. The only way to provide our own function in this way is to place it in a DLL. The hooking API will inject our DLL into Explorer’s process automatically.&lt;/p&gt;&lt;p&gt;Another thing to bear in mind is that the DLL must match the “bitness” of &lt;strong&gt;Explorer.Exe&lt;/strong&gt;, meaning it has to be 32 bit on 32 bit Windows, but it must be 64 bit on 64 bit Windows, because a 64 bit process cannot load a 32 bit DLL (or vice versa).&lt;/p&gt;&lt;p&gt;Add a new project to the existing solution of type “Win32 Application” and select a DLL project with a suitable name, like so (you can check the &lt;strong&gt;Export Symbols &lt;/strong&gt;option if you want):&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_1C904138.png"&gt;&lt;img width="534" height="331" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_7C577991.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Next, we’ll link with the DLL in our hosting EXE, like so:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:38d5cd8b-3c86-42a9-9a55-2be2fbc66f0a" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;#ifdef&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;_WIN64&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;#pragma&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;comment&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;lib&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;..&amp;#92;&amp;#92;x64&amp;#92;&amp;#92;Debug&amp;#92;&amp;#92;RemoverHook.lib&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;#else&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;#pragma&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;comment&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;lib&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;..&amp;#92;&amp;#92;Debug&amp;#92;&amp;#92;RemoverHook.lib&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;#endif&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;We need to link with the correct LIB based on bitness. For x64 projects, the &lt;strong&gt;_WIN64&lt;/strong&gt; macro is defined and so leveraged here.&lt;/p&gt;&lt;p&gt;The next step is to create the actual hook function in the DLL; this must of a certain prototype, as mandated by the &lt;strong&gt;SetWindowsHookEx&lt;/strong&gt; function:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a8658916-fcbb-47ca-a63b-b07dbef1b6e3" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;LRESULT&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;CALLBACK&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; HookFunction(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;code&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WPARAM&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;wParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;LPARAM&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;lParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;) {&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;To make the function visible outside the DLL, we’ll add a DEF file (&lt;strong&gt;File&lt;/strong&gt; / &lt;strong&gt;Add New Item&lt;/strong&gt;) and place the function’s name (&lt;strong&gt;HookFunction&lt;/strong&gt; in the example under the &lt;strong&gt;EXPORTS&lt;/strong&gt; part):&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8f121f6c-f4b5-4110-aad2-7c4921018460" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;LIBRARY&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;EXPORTS&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;HookFunction&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;Before we complete the function’s body, let’s set up the hook in the EXE. After we got a handle to the ReBar control hosting the Task Bar, we need to find out the thread that created it (inside Explorer):&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:36f35d97-b3b1-49f3-95a9-eb381853eab1" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;DWORD&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; tid = ::GetWindowThreadProcessId(hReBar, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;nullptr&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633522(v=vs.85).aspx" target="_blank"&gt;GetWindowThreadProcessId&lt;/a&gt; returns the thread ID of the window’s creator and optionally the process ID as well (not interesting for us, hence the &lt;strong&gt;nullptr&lt;/strong&gt;). Now we can set up the hook:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:582e8d0c-b6fb-4c62-ad18-5b6897bbacf0" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HINSTANCE&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; hDll = ::&lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;GetModuleHandle&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(L&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;RemoverHook.dll&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HOOKPROC&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; hookProc = (&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HOOKPROC&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)::GetProcAddress(hDll, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;HookFunction&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;s_hHook = ::&lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;SetWindowsHookEx&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;WH_CALLWNDPROCRET&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, hookProc, hDll, tid);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;We get the &lt;strong&gt;HINSTANCE&lt;/strong&gt; of the DLL and the address of &lt;strong&gt;HookFunction&lt;/strong&gt; and call &lt;strong&gt;SetWindowsHookEx&lt;/strong&gt; with a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644976(v=vs.85).aspx" target="_blank"&gt;WH_CALLWNDPROCRET&lt;/a&gt; hook type, which provides messages after they have been processed by the target thread; we could have used another hook where we see the message before it gets handled and we could even cancel it, but this is good enough.&lt;/p&gt;&lt;p&gt;The hook handle (&lt;strong&gt;s_hHook&lt;/strong&gt;) is stored in a shared memory section inside the DLL, along with the ReBar control handle, so that both processes (our hosting process and the injected process,&lt;strong&gt; Explorer.Exe&lt;/strong&gt;) have easy access to these:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c6bc4053-de8b-4f6c-be09-e59e15a91705" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;#pragma&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;data_seg&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;Shared&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;__declspec&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;dllexport&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HHOOK&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; s_hHook = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;nullptr&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;__declspec&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;dllexport&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HWND&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; s_hRebarWnd = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;nullptr&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;#pragma&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;data_seg&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;#pragma&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;comment&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(linker, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;/section:Shared,RWS&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;This is a nice trick to get shared memory without resorting to memory mapped file objects. The last line has “RWS” as attributes to the data segment, where “S” is the important part, making it shared. Without it, these variables would be private to each process, just like any global variable in a DLL.&lt;/p&gt;&lt;p&gt;Next, we implement the hook function like so:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f2bfe3c6-2b52-4851-b6ab-2e0897266998" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;LRESULT&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;CALLBACK&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; HookFunction(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;code&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WPARAM&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;wParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;LPARAM&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;lParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;code&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &amp;lt; 0)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; ::CallNextHookEx(s_hHook, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;code&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;wParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;lParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;auto&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; msg = (&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;CWPRETSTRUCT&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;*)&lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;lParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(msg-&amp;gt;message != &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;WM_MOVE&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; || msg-&amp;gt;hwnd != s_hRebarWnd)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; ::CallNextHookEx(s_hHook, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;code&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;wParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;lParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(s_hRebarWnd) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;RECT&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; rc;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;::GetWindowRect(s_hRebarWnd, &amp;amp;rc);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;::SetWindowPos(s_hRebarWnd, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;nullptr&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, 0, 0, rc.right, rc.bottom - rc.top, &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;SWP_NOZORDER&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; | &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;SWP_NOACTIVATE&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; ::CallNextHookEx(s_hHook, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;code&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;wParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#808080;"&gt;lParam&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;If the hook action code is zero or above, we can act. The documentation states that &lt;strong&gt;lParam&lt;/strong&gt; is a pointer to a structure, &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644963(v=vs.85).aspx" target="_blank"&gt;CWPRETSTRUCT&lt;/a&gt;, containing all the information about the message. if it’s in fact &lt;strong&gt;WM_MOVE&lt;/strong&gt; and the window is the ReBar control, then we simply move it to the left in the same way it was done from the hosting executable and that’s it.&lt;/p&gt;&lt;p&gt;One final thing to do – our EXE can’t exit – if it does, the hook is automatically “unhooked”, so a simple call to&lt;strong&gt; Sleep(INFINITE)&lt;/strong&gt; would keep the process alive and unobtrusive.&lt;/p&gt;&lt;p&gt;Just as a final proof, we can open &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" target="_blank"&gt;Process Explorer&lt;/a&gt;, and look at &lt;strong&gt;Explorer.Exe&lt;/strong&gt; for our injected DLL:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_15A1C1E3.png"&gt;&lt;img width="704" height="392" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_64F08941.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you’re feeling like it, you can add some GUI and allow removing and restoring the Start button, if you so desire. The complete source code can be downloaded &lt;a href="http://sdrv.ms/197KfcZ" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2608456" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Internals/default.aspx">Internals</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Fun/default.aspx">Fun</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/64+bit/default.aspx">64 bit</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+C_2B002B00_/default.aspx">Visual C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+8.1/default.aspx">Windows 8.1</category></item><item><title>Getting rid of the Start button in Windows 8.1</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/09/15/getting-rid-of-the-start-button-in-windows-8-1.aspx</link><pubDate>Sun, 15 Sep 2013 15:52:57 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2603885</guid><dc:creator>pavely</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2603885</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2603885</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/09/15/getting-rid-of-the-start-button-in-windows-8-1.aspx#comments</comments><description>&lt;p&gt;Windows 8.1 brings back the famous Start button, but alas – it’s not the good &lt;strong&gt;Start&lt;/strong&gt; button from Windows 7. It’s just yet another way to get to the new Home screen. This makes the Start button (at least for me) completely useless, as there are already several ways to get to the Home screen (Windows key on the keyboard, mouse moved to the bottom left corner, touch devices can press the hardware Start button, the Charms bar has a Start button…).&lt;/p&gt;&lt;p&gt;There are utilities that can simulate the old Windows 7 &lt;strong&gt;Start&lt;/strong&gt; button, if I don’t have such a utility, at least I’d like to get rid of the button, since it takes valuable space on the task bar. But how?&lt;/p&gt;&lt;p&gt;My first guess would be that the &lt;strong&gt;Start&lt;/strong&gt; button is a Window, so it has an &lt;strong&gt;HWND&lt;/strong&gt;. Let’s find it and then get rid of it by closing it or hiding it. How can we find the Start button’s HWND? We turn to our trusted tool, Spy++.&lt;/p&gt;&lt;p&gt;Search (in Windows, if you have Visual Studio or the Windows SDK installed) for “Spy++” or “Spyxx” and run the tool (at this point it doesn’t matter if you run the 32 or 64 bit version). This is how the tool looks like when run:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_66F515F2.png"&gt;&lt;img width="517" height="384" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_6AE1A8DB.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;We need to find the HWND of the Start button. For this we’ll open the &lt;strong&gt;Spy &lt;/strong&gt;menu and select &lt;strong&gt;Find Window…&lt;/strong&gt;. A small window appears with a “bullseye” crosshair which we can drag on top of any window to get some more information:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_65E13A36.png"&gt;&lt;img width="391" height="362" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_0F37C08E.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Click and drag the finder tool over the &lt;strong&gt;Start &lt;/strong&gt;button and then release the mouse button:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_0EADD2B0.png"&gt;&lt;img width="392" height="363" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_17E94C4A.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;(The Handle value itself may be different on your system). Click &lt;strong&gt;OK&lt;/strong&gt; to see the properties of that Window:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_0BC9A12D.png"&gt;&lt;img width="397" height="305" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_1C8DF983.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Clearly, the Window caption is “Start”, so we got our man, so to speak. However, the caption “Start” may be localized, and perhaps it’s called something else on a different UI regional settings. To find the Start button in code, we’ll need something more definite. This is the &lt;strong&gt;Class name &lt;/strong&gt;of the Start button’s Window, which we can find in the &lt;strong&gt;Class &lt;/strong&gt;tab:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_74CC5320.png"&gt;&lt;img width="401" height="308" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_6D91EC70.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In classic Windows, every window belongs to a class. There are predefined classes like “button”, “listbox” and others, but for custom windows, new classes need to be created, as was clearly done with the Start button.&lt;/p&gt;&lt;p&gt;Next, we need to find out the relationship of the Start button’s window to the desktop, so we can find it. Clicking on the Synchronize button shows the Window’s position in the parent/child hierarchy:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/SNAGHTML28304f9_37FE0013.png"&gt;&lt;img width="436" height="285" title="SNAGHTML28304f9" style="display:inline;background-image:none;" alt="SNAGHTML28304f9" src="http://blogs.microsoft.co.il/blogs/pavely/SNAGHTML28304f9_thumb_7C20AC76.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Here we can see that the Start button is a child of a window with a class name of “Shell_TrayWnd”, which is in itself a direct child of the desktop.&lt;/p&gt;&lt;p&gt;Let’s start coding. Create a new Visual Studio C++ Win32 project (a normal EXE or a console app) (you can use any VS version for this (I’ve avoided C++11 specific features). Add an #include for &amp;lt;windows.h&amp;gt;.&lt;/p&gt;&lt;p&gt; In the &lt;strong&gt;main&lt;/strong&gt; (or &lt;strong&gt;WinMain&lt;/strong&gt;) function, we’ll get to the Start button in two steps: first, find that “Shell_TrayWnd” window and then the Start button itself:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0895a689-cb93-4868-9294-9c5155d1f2e9" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:300px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HWND&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; hDesktop = ::&lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;FindWindow&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(L&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;Shell_TrayWnd&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;nullptr&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HWND&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; hStart = ::&lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;FindWindowEx&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(hDesktop, &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;NULL&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, L&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;Start&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;nullptr&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;&lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/ms633499(v=vs.85).aspx" target="_blank"&gt;FindWindow&lt;/a&gt; looks for a top-level window (we can verify with Spy++ that the “&lt;strong&gt;Shell_TrayWnd&lt;/strong&gt;” indeed is top level, but examining the “&lt;strong&gt;Windows&lt;/strong&gt;” tab in the properties window of Spy++. &lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/ms633500(v=vs.85).aspx" target="_blank"&gt;FindWindowEx&lt;/a&gt; looks for a child window, given a parent window. Note that both functions can search for a specific class name, which is what we need. The functions can also search by window title, but that’s too brittle for most purposes, certainly for ours, as the “&lt;strong&gt;Shell_TrayWnd&lt;/strong&gt;” window has no caption.&lt;/p&gt;&lt;p&gt;if we find the Start button, we can make it go away by destroying it (politely) or by simply hiding it (both approaches work equally well):&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6fe21747-889a-4e8d-affd-9e429941bfb9" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(hStart) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#008000;"&gt;//        ::SendMessage(hStart, WM_CLOSE, 0, 0);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;::ShowWindow(hStart, &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;SW_HIDE&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;I’ve commented out the destroying option.&lt;/p&gt;&lt;p&gt;When executed, this little app gets rid of the Start button!&lt;/p&gt;&lt;p&gt;Unfortunately, we’re not done yet. The button is gone, but it left out empty space, which we want to use for the &lt;strong&gt;TaskBar&lt;/strong&gt;. We need to move a sibling window of the Start button, with a class name of “&lt;strong&gt;ReBarWindow32&lt;/strong&gt;” to the left – this is the window that holds the TaskBar itself. We can verify this with Spy++, and I leave that as an exercise to the reader.&lt;/p&gt;&lt;p&gt;So, we continue with a similar searching technique to move the ReBar window like so:&lt;/p&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e65560e6-9058-4fb9-94dd-9197bc9db7bb" style="margin:0px;padding:0px;float:none;display:inline;"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#fff;max-height:500px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HWND&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; hReBar = &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;FindWindowEx&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(hDesktop, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;nullptr&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, L&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;ReBarWindow32&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;nullptr&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(hReBar) {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;RECT&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; rc;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;::GetWindowRect(hReBar, &amp;amp;rc);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;::SetWindowPos(hReBar, &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;NULL&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, 0, 0, rc.right, rc.bottom - rc.top, &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;SWP_NOZORDER&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; | &lt;/span&gt;&lt;span style="background:#ffffff;color:#6f008a;"&gt;SWP_NOACTIVATE&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;p&gt;We locate the window, get it’s bounds into a RECT structure, and move it to the left to position 0,0. Note that if the TaskBar is docked to the left or right (as some people prefer), we’d have to change our code accordingly. I’ll leave that as another exercise for the reader.&lt;/p&gt;&lt;p&gt;Now we’re done, or at least it seems so:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_6F975F15.png"&gt;&lt;img width="655" height="31" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_7AA32E76.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Not quite, unfortunately…&lt;/p&gt;&lt;p&gt;Clicking on the system tray down arrow causes the taskbar to be restored to its former glory… including the Start button. It will not actually show, as it was hidden or closed, but the empty space returns.&lt;/p&gt;&lt;p&gt;What can we do about that? We need to write a hook – which we will in the second part of this post…&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2603885" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows7/default.aspx">Windows7</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Internals/default.aspx">Internals</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Tips/default.aspx">Tips</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+C_2B002B00_/default.aspx">Visual C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+8.1/default.aspx">Windows 8.1</category></item><item><title>Interpreting a Handle’s Access Mask</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/08/19/interpreting-a-handle-s-access-mask.aspx</link><pubDate>Mon, 19 Aug 2013 08:13:38 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2441067</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2441067</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2441067</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/08/19/interpreting-a-handle-s-access-mask.aspx#comments</comments><description>&lt;p&gt;When opening a handle to a kernel object with some &lt;strong&gt;Open*&lt;/strong&gt; Windows API function (e.g. &lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/ms684320(v=vs.85).aspx" target="_blank"&gt;OpenProcess&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/ms684335(v=vs.85).aspx" target="_blank"&gt;OpenThread&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/ms684305(v=vs.85).aspx" target="_blank"&gt;OpenEvent&lt;/a&gt;, …) an access mask must be specified, indicating the type of access requested from the resulting handle. Requiring too much access may cause the call to fail, so a best practice is to require the only access flags that are needed to get the job done.&lt;/p&gt;&lt;p&gt;For example, suppose we want to know when a running process terminates. This requires obtaining a handle to the process in question and calling &lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/ms687032(v=vs.85).aspx" target="_blank"&gt;WaitForSingleObject&lt;/a&gt; on that handle. For this, only the &lt;strong&gt;SYNCHRONIZE&lt;/strong&gt; access is required:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;border-image:none;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;direction:ltr;background-color:white;"&gt;HANDLE hProcess = ::OpenProcess(SYNCHRONIZE, &lt;span&gt;FALSE&lt;/span&gt;, pid);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;direction:ltr;"&gt;&lt;span&gt;if&lt;/span&gt;(hProcess) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;direction:ltr;background-color:white;"&gt;    ::WaitForSingleObject(hProcess, INFINITE);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;direction:ltr;"&gt;    printf(&lt;span&gt;&amp;quot;Process terminated\n&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;What if you have an existing handle, how can you see the access mask associated with the handle? &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896653" target="_blank"&gt;Process Explorer&lt;/a&gt; can help.&lt;/p&gt;&lt;p&gt;Looking at the lower pane when a process is selected (switched to handle view, we can see the access mask column. However, by default, Process Explorer does not show the access mask:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_45C64146.png"&gt;&lt;img width="485" height="140" title="image" style="display:inline;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_3BE31EE5.png" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;Right click the header and select &amp;quot;&lt;strong&gt;Select Columns…&lt;/strong&gt;&amp;quot;. Check the access mask checkbox (at least):&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_2C47738F.png"&gt;&lt;img width="256" height="350" title="image" style="display:inline;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_6A8CEBA8.png" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;Now the access mask is shown, but it&amp;#39;s just a hex value. We need to interpret the bits, which unfortunately Process Explorer doesn&amp;#39;t provide for us. &lt;/p&gt;&lt;p&gt;Sure, we can look up the various API docs and figure out the bits, but I&amp;#39;ve written a simple command line tool to interpret access masks. Running the tool without arguments shows its usage:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_12A3FA83.png"&gt;&lt;img width="696" height="102" title="image" style="display:inline;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_3CF50168.png" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;Let&amp;#39;s try this with some random handles I see in the following Process Explorer snapshot:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_29B8AA84.png"&gt;&lt;img width="541" height="172" title="image" style="display:inline;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_7FBA7B65.png" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;Let&amp;#39;s take handle 0x8, for some key object:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_3EFD04BE.png"&gt;&lt;img width="374" height="243" title="image" style="display:inline;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_795A49A9.png" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;How about handle 0x1c?&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_289094FC.png"&gt;&lt;img width="379" height="242" title="image" style="display:inline;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_69A0E36A.png" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;This tool turned out to be useful for me occasionally, and maybe it will help you too.&lt;/p&gt;&lt;p&gt;You can download the tool from &lt;a href="http://sdrv.ms/16VRgNo" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2441067" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Internals/default.aspx">Internals</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Native+Development/default.aspx">Native Development</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+C_2B002B00_/default.aspx">Visual C++</category></item><item><title>My first PluralSight course has been published!</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/08/08/my-first-pluralsight-course-has-been-published.aspx</link><pubDate>Thu, 08 Aug 2013 09:57:09 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2376411</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2376411</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2376411</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/08/08/my-first-pluralsight-course-has-been-published.aspx#comments</comments><description>&lt;p&gt;In the last few months, I’ve been working on a course for &lt;a href="http://www.pluralsight.com/training" target="_blank"&gt;PluralSight&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Creating a video course is not easy, as I found out first hand. In fact, it’s more difficult than writing a book. With a book, I can change a sentence or a paragraph, at any time and any place. A video course is different… changes are hard, and recording sessions cannot be done just anywhere. But I’ve learned a lot from the experience, which should make next courses a bit easier…&lt;/p&gt;&lt;p&gt;My first course is about a favorite subject of mine, &lt;a href="http://pluralsight.com/training/Courses/TableOfContents/windows-internals" target="_blank"&gt;Windows Internals&lt;/a&gt;. This deals with the way Windows works, all the essential terms are there, such as processes, threads, virtual memory, user and kernel mode, device drivers and others. I’m showing various tools that can be used to look at these concepts, as well as some code, mostly in C++, but some in .NET. The course is pretty long, over six and a half hours, and I’m not nearly done. I plan to create a “part 2” for this, as there are topics I didn’t get a chance to cover in depth.&lt;/p&gt;&lt;p&gt;If you’re a &lt;strong&gt;PluralSight&lt;/strong&gt; subscriber, give the course a look!&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2376411" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Threading/default.aspx">Threading</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows7/default.aspx">Windows7</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Internals/default.aspx">Internals</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/WinDbg/default.aspx">WinDbg</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Native+API/default.aspx">Native API</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Device+Drivers/default.aspx">Device Drivers</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+8/default.aspx">Windows 8</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+C_2B002B00_/default.aspx">Visual C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio+2012/default.aspx">Visual Studio 2012</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/PluralSight/default.aspx">PluralSight</category></item><item><title>Extreme DevCon 2013</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/07/15/extreme-devcon-2013.aspx</link><pubDate>Mon, 15 Jul 2013 18:08:53 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2262237</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2262237</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2262237</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/07/15/extreme-devcon-2013.aspx#comments</comments><description>&lt;p&gt;Next week, John Bryce Training, along with some of its partners, set up a two day conference named &lt;a href="http://www.devcon.jbh.co.il/" target="_blank"&gt;Extreme Dev Con 2013&lt;/a&gt;, on the 22nd and 23rd of July in Hertzliya (Israel). The conference consists mainly of full one-day seminars, several happening at the same time (naturally).&lt;/p&gt;&lt;p&gt;I will be presenting a &lt;a href="http://www.devcon.jbh.co.il/?page=seminars&amp;amp;id=11240" target="_blank"&gt;full day seminar&lt;/a&gt;, titled something like “.NET deep dive for performance”. The rough topics are listed in the above link, but basically I will cover various topics that somehow relate to that elusive thing called “performance”. From process and AppDomains, through the garbage collector and friends, threads and tasks, perhaps some C# 5.0 with &lt;strong&gt;async&lt;/strong&gt; and &lt;strong&gt;await&lt;/strong&gt;, and also profiling, I will try to cover as much as I can with the time frame given. I will use a lot of code demos (and some tools) to make the theoretical concepts more concrete.&lt;/p&gt;&lt;p&gt;Registration is not free, unfortunately, but this should be worth it if you’re a .NET developer who cares about the code you write, and want to gain a deeper understanding to the way the CLR works and gain some practical insights into the framework’s power. &lt;/p&gt;&lt;p&gt;Register &lt;a href="http://devcon.jbh.co.il/?page=registration" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;I hope to see you there!&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2262237" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Threading/default.aspx">Threading</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/CLR/default.aspx">CLR</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET+Profiling+API/default.aspx">.NET Profiling API</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/WinDbg/default.aspx">WinDbg</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_+5.0/default.aspx">C# 5.0</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio+2012/default.aspx">Visual Studio 2012</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio+2013/default.aspx">Visual Studio 2013</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DevCon+2013/default.aspx">DevCon 2013</category></item><item><title>Build 2013 Summary</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/06/29/build-2013-summary.aspx</link><pubDate>Sat, 29 Jun 2013 05:07:09 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2215007</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2215007</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2215007</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/06/29/build-2013-summary.aspx#comments</comments><description>&lt;p&gt;The Microsoft Build 2013 conference is now over, so it’s time for some summaries and impressions. All the following is my personal thoughts from my viewpoint, and may not reflect the way things actually are. Last caveat – some of the information is based on the sessions I attended. Naturally, I couldn’t attend most sessions, and I may not even remember all info given in the session I attended. Still…&lt;/p&gt;&lt;p&gt;The conference was 3 days in length. With about 14 sessions going on at the same time slot, this is too short a conference; 4 days would have been better. Sure, all the sessions are recorded and will be available for viewing – but that’s not the point. If I just wanted to view sessions, I wouldn’t need to go to Build at all. The point of Build (besides the “experience” in general), is to be able to talk to people, especially from Microsoft and perhaps get some answers to nagging questions.&lt;/p&gt;&lt;h2&gt;&lt;/h2&gt;&lt;h2&gt;So, what’s new?&lt;/h2&gt;&lt;p&gt;Nothing earthshaking. The conference date was unusual – not the October/November timeframe, but late June. This was (to me) a hint that Microsoft had something new to show the world; alas, I was disappointed. There was nothing really new; I can’t shake the feeling that if the dates were in October/November, there would have been truly new things to show.&lt;/p&gt;&lt;p&gt;Windows 8.1 – this is the next version of Windows. Windows 8 was called “Windows Re-imagined”, and Windows 8.1 is called “Windows Refined”, which is pretty accurate. No earth-shaking changes, but refinements and improvements across the board. Is that really worthy of a Build conference? I don’t think so.&lt;/p&gt;&lt;p&gt;So, what’s new? Here are some things I found interesting:&lt;/p&gt;&lt;p&gt;The &lt;strong&gt;Start &lt;/strong&gt;button – a lot have been said about the return of the Start button (not quite the Jedi, unfortunately). There is a &lt;strong&gt;Start&lt;/strong&gt; button on the &lt;strong&gt;TaskBar&lt;/strong&gt; now, but clicking it does not open a Windows 7 style menu, but instead shows the tiles, although it maintains the desktop background. A new &lt;strong&gt;Apps&lt;/strong&gt; view is available when swiping up (or pressing a down arrow at the bottom of the Tile screen). So now there are things in the Home Tile screen, but not everything (as was in Windows 8). You can opt-in and select which apps (Modern or Desktop) to show in the home screen.&lt;/p&gt;&lt;p&gt;This is pretty much the way it works in Windows Phone. And while in the Phone this is a good experience, in Windows 8.1 it’s not quite there. The problem is that the Apps view is still a mess; in the Phone it’s a nice list with search capabilities. In Windows 8.1 it’s a mess of apps, although the Search helps. Since Windows 8.1 is running on various form factors, but always larger than the Phone, this seems a below par experience. The new &lt;strong&gt;Start&lt;/strong&gt; button is mostly useless.&lt;/p&gt;&lt;p&gt;However, there is a new option to boot to desktop. Here’s the &lt;strong&gt;TaskBar&lt;/strong&gt; properties &lt;strong&gt;Navigation&lt;/strong&gt; tab:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_3490FFF2.png"&gt;&lt;img width="320" height="380" title="image" style="display:inline;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_1F845347.png" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;&lt;h2&gt;Windows Azure&lt;/h2&gt;&lt;p&gt;Windows Azure is Microsoft’s cloud platform, and its capabilities are truly amazing. It’s not just the capabilities themselves, it’s much more than that. There are so many services exposed that rely on the Azure infrastructure, that developers are sure to find services that would make their lives easier when building all sorts of apps, from server based apps to mobile client apps. The number of services and the rapid pace of their inclusion is staggering. I remember not so long ago, when Azure was young (and it still is), where the basics where there, but not much more: web role, worker role, table and blob storage, queues and a basic service bus. Azure has come a long way since then with many services too long to list here. I recommend watching the second day keynote to get a sense of the new stuff.&lt;/p&gt;&lt;h2&gt;Visual Studio 2013 and .NET 4.5.1&lt;/h2&gt;&lt;p&gt;Microsoft unveiled Visual Studio 2013 preview, and at the same time released &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=39305" target="_blank"&gt;Update 3 for Visual Studio 2012&lt;/a&gt;. As was noted in Ballmer’s keynote, Microsoft has been moving to rapid release cycles for all (or at least most) products, including Visual Studio. many feature enhancements exist in the editor, the &lt;strong&gt;Edit and Continue &lt;/strong&gt;feature is now supported for 64 bit .NET projects (as well as 32 bit), XAML intellisense can now help with standard Windows 8 / Windows Phone &lt;strong&gt;StaticResource&lt;/strong&gt; values, and more. Debugging has been enhanced by a new hub for profiling and call stack information for async/await debugging. This means that when a breakpoint is placed after an &lt;strong&gt;await &lt;/strong&gt;operation completes, the call stack shown includes call information before and after the await call.&lt;/p&gt;&lt;p&gt;To gain some of these features, .NET 4.5.1 is required and is installed automatically with the VS 2013 preview. There are some improvements in this release as well, but as you can guess from the version number, nothing earth-shaking.&lt;/p&gt;&lt;h2&gt;C++&lt;/h2&gt;&lt;p&gt;C++ got a few new features. C++ 11 features that were part of a compiler CTP back in November 2012 were incorporated in release form. &lt;strong&gt;async&lt;/strong&gt;/&lt;strong&gt;await &lt;/strong&gt;is not there yet (yes, I mean roughly the same feature as in C# – implemented with the &lt;strong&gt;concurrency::task&amp;lt;&amp;gt;&lt;/strong&gt; class), by the way. In &lt;a href="http://channel9.msdn.com/Events/Build/2013/2-306" target="_blank"&gt;Heb Sutter’s talk&lt;/a&gt;, he said async.await (in C++) should be available after VS 2013 ships, sometime later this year. If you’re a C++ developer, you should watch his talk.&lt;/p&gt;&lt;p&gt;In the VS 2013 IDE, C++ enjoys some new features. One of them is the ability to format source code with rules for formatting, such as indentation, spaces, etc., just like in C#. I think it’s about time, and is a great feature. Pressing Ctrl+K,D (just like in C#) corrects the source code to comply with these formatting rules. Here’s a snapshot from Tools / Options:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_69F066E9.png"&gt;&lt;img width="412" height="242" title="image" style="display:inline;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_6941CDB6.png" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;&lt;h2&gt;Windows Runtime and Store apps&lt;/h2&gt;&lt;p&gt;Naturally, there’s a lot of focus on these areas. Many new UI controls have been added to WinRT, usable by all languages leveraging XAML (C++ and .NET) and also from JavaScript (WinJS). Some new &lt;strong&gt;Binding&lt;/strong&gt; properties have been added, getting closer to the Silverlight/WPF set, including &lt;strong&gt;UpdateSourceTrigger&lt;/strong&gt;, &lt;strong&gt;FallbackValue&lt;/strong&gt; and &lt;strong&gt;TargetNullValue&lt;/strong&gt;. Curiously, no &lt;strong&gt;StringFormat&lt;/strong&gt; just yet. A new markup extension, &lt;strong&gt;ThemeResource&lt;/strong&gt; allows for automatic theme changes (Dark, Light, HighContrast) without restarting the app. It’s similar to WPF’s &lt;a href="http://msdn.microsoft.com/EN-US/library/vstudio/ms748942(v=vs.100).aspx" target="_blank"&gt;DynamicResource&lt;/a&gt;, but only works for theme changes.&lt;/p&gt;&lt;p&gt;Other improvements in the core WinRT exist as well. I suggest watching the relevant sessions to get all the details.&lt;/p&gt;&lt;h2&gt;What about the desktop?&lt;/h2&gt;&lt;p&gt;Windows Store apps are good and well, but what about desktop apps? It seems Microsoft has finally realized that although there are nearly 100,000 apps in the Windows 8 store, there are millions of desktop apps out there. These apps were neglected since the Windows 8 original release, and now some balance is being restored. There were sessions about desktop apps and new features they can use, such as &lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/hh437371(v=vs.85).aspx" target="_blank"&gt;DirectComposition&lt;/a&gt; (which is also the underlying composition engine in Store apps XAML engine), &lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/dd370990(v=vs.85).aspx" target="_blank"&gt;Direct2D&lt;/a&gt; (applicable to Store apps as well, of course) and some other features. &lt;/p&gt;&lt;p&gt;Still, this is not enough. Desktop apps are neglected. There was no mention of new features in WPF; this is really annoying, considering the many new UI controls added to WinRT. Some of these would be useful in the WPF space as well. However, WPF was mentioned &lt;strong&gt;twice &lt;/strong&gt;in the second keynote! I though Microsoft may have forgot that WPF exists.&lt;/p&gt;&lt;p&gt;In the native C++ world, for desktop apps, XAML cannot currently be used. Microsoft seems to insist that C++ developers would have to continue using antiquated libraries, such as &lt;strong&gt;MFC&lt;/strong&gt;, or some open source cross platform library, such as Qt. There is currently no decent native library from Microsoft for desktop apps. Since using WinRT types from desktop apps is possible, and in fact most can be used, I find this restriction artificial and unjust. There’s no reason to prevent XAML from working in desktop apps, and this seems to suggest Microsoft has not yet fully understands the importance of desktop apps, not just for existing apps, but for new apps as well. Not all apps benefit from a touch interface; some are only feasible with a mouse, menus and other common desktop app features.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Windows Phone&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Sorely lacking new features and announcements was Windows Phone. There was no mentioning of Windows Phone 8.1 or any other new version, for that matter. It seems Microsoft chose to focus on Windows 8.1 as far as client platforms go. I managed to speak to one member of the Windows Phone team, and he basically said that this time all focus went to Windows 8.1, and (of course) he can’t talk about Windows Phone future.&lt;/p&gt;&lt;p&gt;There were about 20 sessions on Windows Phone, but there was nothing new, so this is more suitable for a TechEd conference, where the present is discussed. &lt;strong&gt;Build &lt;/strong&gt;is mostly about the future, and this opportunity to talk about the Phone has been missed entirely.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;There were other interesting things to look at, such as the new Kinect (part of XBOX One, but will be available for the PC as well, sometime in 2014) and some interesting innovations, mostly shown in the keynotes. Overall, this is not one of the best Build conferences. Hopefully, next Builds will be better.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2215007" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Graphics/default.aspx">Graphics</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Azure/default.aspx">Azure</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/64+bit/default.aspx">64 bit</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DirectX/default.aspx">DirectX</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Games/default.aspx">Games</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+Phone/default.aspx">Windows Phone</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/BUILD/default.aspx">BUILD</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+8/default.aspx">Windows 8</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B00_11/default.aspx">C++11</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+Runtime/default.aspx">Windows Runtime</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio+2012/default.aspx">Visual Studio 2012</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio+2013/default.aspx">Visual Studio 2013</category></item><item><title>Kernel debugging with a Hyper-V virtual machine</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/06/25/kernel-debugging-with-a-hyper-v-virtual-machine.aspx</link><pubDate>Wed, 26 Jun 2013 03:23:13 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2204036</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2204036</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2204036</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/06/25/kernel-debugging-with-a-hyper-v-virtual-machine.aspx#comments</comments><description>&lt;p&gt;One of the best ways of investigating the way Windows works is through a kernel debugger. Windows supports a local kernel debugging mode that can be activated in one of two ways:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Setup windows to run in local debugging mode by running &lt;strong&gt;bcdedit /debug on&lt;/strong&gt; from an elevated command prompt and then restart. Finally, run &lt;a href="http://en.wikipedia.org/wiki/WinDbg" target="_blank"&gt;WinDbg&lt;/a&gt; and select &lt;strong&gt;File&lt;/strong&gt; / &lt;strong&gt;Kernel Debug…&lt;/strong&gt; from the menu and then select the &lt;strong&gt;Local&lt;/strong&gt; tab and click OK:&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_0550A3E3.png"&gt;&lt;img width="323" height="231" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_775E124D.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The main downside here is the need for restart, and more subtly – some apps behave strangely when the debug flag is on.&lt;/p&gt;&lt;p&gt;2. Use the &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb897415.aspx" target="_blank"&gt;LiveKD&lt;/a&gt; tool from &lt;a href="http://technet.microsoft.com/en-US/sysinternals" target="_blank"&gt;SysInternals&lt;/a&gt;. This doesn’t require the debug flag – just copy &lt;strong&gt;Livekd.exe&lt;/strong&gt; to the folder where WinDbg is and run &lt;strong&gt;Livekd –w &lt;/strong&gt;from an elevated command prompt.&lt;/p&gt;&lt;p&gt;The problem with both approaches is the fact that breakpoints cannot be set – the system is running. For breakpoints, another system is required. Using a second physical computer is usually inconvenient, if at all possible. Fortunately, a Hyper-V VM can be set up as a target system for kernel debugging with some simple configuration without having to run various scripts. Here’s how to do it:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Open the settings of the VM and expose a COM port as a named pipe (COM1 in this example):&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_50DBE368.png"&gt;&lt;img width="417" height="269" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_677ADF57.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The pipe name doesn’t matter.&lt;/p&gt;&lt;p&gt;2. in the VM, run &lt;strong&gt;msconfig.exe &lt;/strong&gt;and select the &lt;strong&gt;Boot &lt;/strong&gt;tab&lt;strong&gt;:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_40F8B072.png"&gt;&lt;img width="421" height="284" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_7A5B74CF.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;3. Click the &lt;strong&gt;Advanced Options…&lt;/strong&gt; button and check the &lt;strong&gt;Debug &lt;/strong&gt;checkbox and select &lt;strong&gt;COM1&lt;/strong&gt; as the debug port. Leave the default baud rate as is:&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_293D650D.png"&gt;&lt;img width="418" height="416" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_1316ADE1.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;4. Restart the VM for the settings to take effect. Once this is done, the system will always start in debug mode, so nothing else is required on this target machine.&lt;/p&gt;&lt;p&gt;5. On the host machine, run &lt;strong&gt;WinDbg.exe&lt;/strong&gt; elevated, and select &lt;strong&gt;File&lt;/strong&gt; / &lt;strong&gt;Kernel Debug…&lt;/strong&gt; menu option. Enter the pipe name as &lt;strong&gt;\\.\pipe\pipename&lt;/strong&gt;, where &lt;strong&gt;pipename&lt;/strong&gt; is the pipe name given in the VM settings (&lt;strong&gt;debug&lt;/strong&gt; in our example):&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/pavely/image_73F03EA8.png"&gt;&lt;img width="421" height="301" title="image" style="display:inline;background-image:none;" alt="image" src="http://blogs.microsoft.co.il/blogs/pavely/image_thumb_30A474E1.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;6. Check the Pipe and Reconnect checkboxes. Click OK. Now the debugger command window shows this:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Microsoft (R) Windows Debugger Version 6.2.9200.16384 AMD64&lt;br /&gt;
Copyright (c) Microsoft Corporation. All rights reserved.&lt;/strong&gt;&lt;/p&gt;&lt;strong&gt;
&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;Opened \\.\pipe\debug&lt;br /&gt;
Waiting to reconnect..&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;7. Now click the Break toolbar button (or select Debug / Break from the menu, or hit Ctrl+Break). After a few seconds, the command windows will show the following, and the VM is completely frozen (this is from a Windows 7 32 bit VM):&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Connected to Windows 7 7600 x86 compatible target at (Tue Jun 25 20:08:54.926 2013 (UTC - 7:00)), ptr64 FALSE&lt;br /&gt;
Kernel Debugger connection established.&lt;br /&gt;
Symbol search path is: SRV*c:\Symbols*&lt;/strong&gt;&lt;strong&gt;http://msdl.microsoft.com/download/symbols&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;
Executable search path is: &lt;br /&gt;
Windows 7 Kernel Version 7600 MP (2 procs) Free x86 compatible&lt;br /&gt;
Product: WinNt, suite: TerminalServer SingleUserTS Personal&lt;br /&gt;
Built by: 7600.17207.x86fre.win7_gdr.130104-1435&lt;br /&gt;
Machine Name:&lt;br /&gt;
Kernel base = 0x82610000 PsLoadedModuleList = 0x82758810&lt;br /&gt;
Debug session time: Tue Jun 25 20:08:50.420 2013 (UTC - 7:00)&lt;br /&gt;
System Uptime: 0 days 5:09:28.494&lt;br /&gt;
Break instruction exception - code 80000003 (first chance)&lt;br /&gt;
*******************************************************************************&lt;br /&gt;
*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*&amp;nbsp;&amp;nbsp; You are seeing this message because you pressed either&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CTRL+C (if you run console kernel debugger) or,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CTRL+BREAK (if you run GUI kernel debugger),&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*&amp;nbsp;&amp;nbsp; on your debugger machine&amp;#39;s keyboard.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THIS IS NOT A BUG OR A SYSTEM CRASH&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
* If you did not intend to break into the debugger, press the &amp;quot;g&amp;quot; key, then&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
* press the &amp;quot;Enter&amp;quot; key now.&amp;nbsp; This message might immediately reappear.&amp;nbsp; If it *&lt;br /&gt;
* does, press &amp;quot;g&amp;quot; and &amp;quot;Enter&amp;quot; again.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br /&gt;
*******************************************************************************&lt;br /&gt;
nt!RtlpBreakWithStatusInstruction:&lt;br /&gt;
8267a754 cc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;br /&gt;
&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;You can now run any legal command that affects the target VM. If you don’t have symbols set up correctly for Microsoft’s symbol server, set the symbols path (&lt;strong&gt;File&lt;/strong&gt; / &lt;strong&gt;Symbol File Path&lt;/strong&gt;) to something like &lt;strong&gt;SRV*c:\Symbols*http://msdl.microsoft.com/download/symbols&lt;/strong&gt; (to connect to Microsoft’s symbols server and cache symbol files in c:\symbols) or more simply use the &lt;strong&gt;.symfix&lt;/strong&gt; command, followed by &lt;strong&gt;.reload&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Use the &lt;strong&gt;.reload&lt;/strong&gt; command in any case, to make sure required symbols are loaded. Then you can use the &lt;strong&gt;lm&lt;/strong&gt; command to list the loaded kernel modules.&lt;/p&gt;&lt;p&gt;You can try something simple, like breaking when new processes are created:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;bp nt!NtCreateUserProcess&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Issue the &lt;strong&gt;g&lt;/strong&gt; (go) command and do something in the VM that requires creating a process. A breakpoint like the following will hit:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Breakpoint 0 hit&lt;br /&gt;
nt!NtCreateUserProcess:&lt;br /&gt;
82866423 68b8060000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; push&amp;nbsp;&amp;nbsp;&amp;nbsp; 6B8h&lt;br /&gt;
&lt;/strong&gt;Enter the &lt;strong&gt;!process –1 0&lt;/strong&gt; to find out which process invoked &lt;strong&gt;NtCreateProcess&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;PROCESS 85c84cb0&amp;nbsp; SessionId: 1&amp;nbsp; Cid: 06d4&amp;nbsp;&amp;nbsp;&amp;nbsp; Peb: 7ffda000&amp;nbsp; ParentCid: 0664&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DirBase: bec0d300&amp;nbsp; ObjectTable: 97376718&amp;nbsp; HandleCount: 671.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Image: explorer.exe&lt;br /&gt;
&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;This is &lt;strong&gt;Explorer.exe&lt;/strong&gt;. The sky is the limit from here…&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2204036" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Internals/default.aspx">Internals</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/WinDbg/default.aspx">WinDbg</category></item><item><title>WDCIL Presentation and Demos</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/06/18/wdcil-presentation-and-demos.aspx</link><pubDate>Tue, 18 Jun 2013 19:48:13 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2175163</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2175163</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2175163</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/06/18/wdcil-presentation-and-demos.aspx#comments</comments><description>&lt;p&gt;This evening I gave a talk on the &lt;a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx" target="_blank"&gt;Task Parallel Library&lt;/a&gt; (TPL) and the &lt;a href="http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx" target="_blank"&gt;asynchronous programming features of C# 5.0&lt;/a&gt; &amp;amp; .NET 4.5 at the Israeli Web developers user group. Thank you all for coming, I had a lot of fun!&lt;/p&gt;&lt;p&gt;Although the TPL has been around in release for for more than 3 years, I’m still surprised to find developers who know little about and don’t use it. This is unfortunate, as I consider the TPL one of the best parts of .NET. I wish more developers learn it and use it. The same goes for C# 5.0. For those who attended, I gave away a free copy to one lucky winner of my book, &lt;a href="http://www.amazon.com/Windows-Presentation-Foundation-4-5-Cookbook/dp/184968622X/ref=tmm_pap_title_0" target="_blank"&gt;WPF 4.5 Cookbook&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;As promised, here is the SkyDrive link to the presentation and demos, some of which I didn’t show because of time constraints.&lt;/p&gt;&lt;p&gt;Link: &lt;a title="http://sdrv.ms/13Z5L0U" href="http://sdrv.ms/13Z5L0U"&gt;http://sdrv.ms/13Z5L0U&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2175163" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Threading/default.aspx">Threading</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Task+Parallel+Library/default.aspx">Task Parallel Library</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_+5.0/default.aspx">C# 5.0</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET+4.5/default.aspx">.NET 4.5</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Visual+Studio+2012/default.aspx">Visual Studio 2012</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Book/default.aspx">Book</category></item><item><title>My C# 6.0 Wish List</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/06/05/my-c-6-0-wish-list.aspx</link><pubDate>Wed, 05 Jun 2013 10:33:15 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2119565</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2119565</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2119565</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/06/05/my-c-6-0-wish-list.aspx#comments</comments><description>&lt;p&gt;I’m on a wish list streak, so why not wish myself new features in C# 6.0?&lt;/p&gt;&lt;p&gt;There has been no public talk about C# 6.0 (or the next version of .NET, for that matter). Still, I imagine someone is working on that at Microsoft (maybe not &lt;a href="http://en.wikipedia.org/wiki/Anders_Hejlsberg" target="_blank"&gt;Anders&lt;/a&gt;, who seems to prefer the &lt;a href="http://en.wikipedia.org/wiki/Javascript" target="_blank"&gt;JavaScript&lt;/a&gt; world, with his &lt;a href="http://en.wikipedia.org/wiki/Typescript" target="_blank"&gt;TypeScript&lt;/a&gt; language); hopefully, others have taken the lead for the future of C#.&lt;/p&gt;&lt;p&gt;Firstly, it must be well understood that adding features to a language is a big deal. Once added, these can never be removed. Whereas features to the .NET framework itself can be “deprecated” in future versions, and even eventually removed, languages don’t have that luxury. Someone somewhere may have used a feature you want removed, but you can’t because someone may have used it.&lt;/p&gt;&lt;p&gt;This is why adding features to C# is not just about throwing anything that comes to mind; features must be valuable in some sense, they must serve a purpose coming from necessity, or from the realization that something worthy is lacking.&lt;/p&gt;&lt;p&gt;That said, the following list is not a result of a complete or thorough considerations of various factors; it’s just some things I think can benefit the language and (of course) the developers that use it.&lt;/p&gt;&lt;h2&gt;1. Generic operator constraints&lt;/h2&gt;&lt;p&gt;I’ve been asking for that for years… and still hope to get it. The following code does not compile:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; T Sum&amp;lt;T&amp;gt;(&lt;span&gt;params&lt;/span&gt; T[] values) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;if&lt;/span&gt;(values == &lt;span&gt;null&lt;/span&gt; || values.Length == 0) &lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;default&lt;/span&gt;(T);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    T sum = values[0];&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;for&lt;/span&gt;(&lt;span&gt;int&lt;/span&gt; i = 1; i &amp;lt; values.Length; i++)&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        sum += values[i];&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;return&lt;/span&gt; sum;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The compiler refuses to use the + or += operators with an unconstraint generic type. Not all types have the + operator. The obvious solution is to constrain the generic parameter:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; T Sum&amp;lt;T&amp;gt;(&lt;span&gt;params&lt;/span&gt; T[] values) &lt;span&gt;where&lt;/span&gt; T : &lt;span&gt;operator&lt;/span&gt;+ {&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;However, that is not currently supported. The only supported constraints are base class, interfaces and a public default constructor. There may be reasons why this is not supported,&amp;nbsp; but I think there are better reasons to have it.&lt;/p&gt;&lt;p&gt;Technically, we can get a similar effect that works with the C# 4.0 &lt;a href="http://msdn.microsoft.com/EN-US/library/vstudio/dd264741(v=vs.110).aspx" target="_blank"&gt;dynamic&lt;/a&gt; keyword:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; dynamic Sum(&lt;span&gt;params&lt;/span&gt; dynamic[] values) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;if&lt;/span&gt;(values == &lt;span&gt;null&lt;/span&gt; || values.Length == 0) &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    dynamic sum = values[0];&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;for&lt;/span&gt;(&lt;span&gt;int&lt;/span&gt; i = 1; i &amp;lt; values.Length; i++)&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        sum += values[i];&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;return&lt;/span&gt; sum;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This compiles and works correctly, but sacrifices type safety and performance, because the calls work through reflection (or custom dynamic binding if the object supports it), which may not be good enough for some scenarios. It does have an interesting advantage – it can work on values of multiple types, such as adding a vector to a point (not strictly mathematically correct, but useful in practice), or multiplying a matrix by a vector.&lt;/p&gt;&lt;p&gt;With operator constraints, it would be possible to (e.g.) create a single class to represent a mathematical entity that works with different precisions. For example:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; Matrix&amp;lt;T&amp;gt; &lt;span&gt;where&lt;/span&gt; T : &lt;span&gt;operator&lt;/span&gt;+, &lt;span&gt;operator&lt;/span&gt;-, &lt;span&gt;operator&lt;/span&gt;*, &lt;span&gt;operator&lt;/span&gt;/ {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; Matrix&amp;lt;T&amp;gt; &lt;span&gt;operator&lt;/span&gt;+(Matrix&amp;lt;T&amp;gt; a, Matrix&amp;lt;T&amp;gt; b) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;//...&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This would allow a Matrix of &lt;strong&gt;double&lt;/strong&gt;, &lt;strong&gt;float&lt;/strong&gt;, &lt;strong&gt;int&lt;/strong&gt;, &lt;a href="http://msdn.microsoft.com/EN-US/library/dd268287(v=VS.110,d=hv.2).aspx" target="_blank"&gt;BigInteger&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.numerics.complex.aspx" target="_blank"&gt;Complex&lt;/a&gt; and any other type supporting these operators.&lt;/p&gt;&lt;h2&gt;2. Auto implemented interfaces&lt;/h2&gt;&lt;p&gt;An interface is an abstract entity, requiring implementation to be used. For example, calling &lt;a href="http://msdn.microsoft.com/EN-US/library/windowsphone/develop/system.array.sort(v=vs.105).aspx" target="_blank"&gt;Array.Sort&lt;/a&gt; with an array and an &lt;a href="http://msdn.microsoft.com/EN-US/library/windowsphone/develop/system.collections.icomparer(v=vs.105).aspx" target="_blank"&gt;IComparer&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/8ehhxeaf(v=vs.105).aspx" target="_blank"&gt;IComparer&amp;lt;T&amp;gt;&lt;/a&gt; implementation can customize the way sorting works. For that, we have to create a class that implements the interface for just this purpose:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; Book {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; Author { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; DateTime Published { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; BookDateComparer : IComparer&amp;lt;Book&amp;gt; {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; Compare(Book x, Book y) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;return&lt;/span&gt; x.Published.CompareTo(y.Published);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;Book[] books = ...;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;Array.Sort(books, &lt;span&gt;new&lt;/span&gt; BookDateComparer());&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This doesn’t seem too bad, but we’re losing code locality – the &lt;strong&gt;BookDateComparer&lt;/strong&gt; class may be defined far away from where it’s used. I’d rather do this:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;Array.Sort(books, &lt;span&gt;new&lt;/span&gt; IComparer&amp;lt;Book&amp;gt; {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                            &lt;span&gt;int&lt;/span&gt; CompareTo(Book x, Book y) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                                &lt;span&gt;return&lt;/span&gt; x.Published.CompareTo(y.Published);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                            }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                  });&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;And we have code locality. All methods in such interface need not have any visibility modifier – it’s really just for this implementation – it’s inaccessible to any other piece of code. We can also have other members (fields, properties) – these too need no visibility modifiers; they are private by definition.&lt;/p&gt;&lt;p&gt;Technically, simple interfaces such as &lt;strong&gt;IComparer&amp;lt;T&amp;gt;&lt;/strong&gt; can be worked around with a generic class like so:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; GenericComparer&amp;lt;T&amp;gt; : IComparer&amp;lt;T&amp;gt; {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    Func&amp;lt;T, T, &lt;span&gt;int&lt;/span&gt;&amp;gt; _comparator;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; GenericComparer(Func&amp;lt;T, T, &lt;span&gt;int&lt;/span&gt;&amp;gt; comparator) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        _comparator = comparator;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; Compare(T x, T y) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;return&lt;/span&gt; _comparator(x, y);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;height:36px;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;Array.Sort(books, &lt;span&gt;new&lt;/span&gt; GenericComparer&amp;lt;Book&amp;gt;((x, y) =&amp;gt; x.Published.CompareTo(y.Published)));&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;But this is insufficient for more complex interfaces, hence the feature suggestion.&lt;/p&gt;&lt;h2&gt;3. Operators in interfaces&lt;/h2&gt;&lt;p&gt;While on the subject of interfaces, I would appreciate the ability to define operators in an interface, so that implementations would be forced to support them:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;interface&lt;/span&gt; IVectorOperations {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    Vector &lt;span&gt;operator&lt;/span&gt; +(Vector v);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    Vector &lt;span&gt;operator&lt;/span&gt; -(Vector v);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This would allow executing operators through interfaces, which currently cannot work. From a syntax perspective, it looks a bit strange, as operators in C# are implemented as static methods. But using static methods in an interface is illogical. So I suggest the binary operators accept just one argument (which is the second), the first being the instance itself (this). That’s similar to how operators are typically implemented in C++.&lt;/p&gt;&lt;p&gt;The implementation syntax can stay the same (&lt;strong&gt;static&lt;/strong&gt; method) or adopt this syntax (I’m not sure which is best).&lt;/p&gt;&lt;h2&gt;4. Class-level and method-level using&lt;/h2&gt;&lt;p&gt;The using statement (as bringer of namespaces for the compiler to search through) can only be used in the global section of the file and inside a namespace declaration. For example:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;namespace&lt;/span&gt; DemoApp {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;using&lt;/span&gt; System.Threading;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;class&lt;/span&gt; Demo {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Sometimes, however, certain types are needed in a class scope, or even a method scope. But using can’t be used there, forcing us to use the full name of the class, add a using at an allowed scope (possibly polluting other methods and classes) or use aliases (with using in allowed scopes). All these solutions work, but again, may cause issues and are against code locality. I would prefer something like this:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; DoWork() {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    Task.Run(() =&amp;gt; {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;//...&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    });&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This constrains the using to a particular method where the &lt;strong&gt;Task&lt;/strong&gt; class is needed, and may be the only method that needs it.&lt;/p&gt;&lt;h2&gt;5. Multiple private inheritance (“mixins”)&lt;/h2&gt;&lt;p&gt;Don’t be alarmed – I don’t want real multiple inheritance as in C++ – this would require a major change in the CLR, and in any case I don’t want that. Still, looking at C++, the concept of private inheritance has its advantages; the inheritance is of implementation only, invisible outside the class. Here’s my suggested syntax:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; Animal {... }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;interface&lt;/span&gt; IMammal { ...    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; Carnivore {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; EatMeat() { ... }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; Sleepy {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Sleep() { ... }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; Tiger : Animal, IMammal, &lt;span&gt;private&lt;/span&gt; Carnivore, Sleepy {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Eat() {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        EatMeat();    &lt;span&gt;// from Carnivore&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Rest() {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        Sleep();    &lt;span&gt;// from Sleepy&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The Tiger class has two private inheritance classes: &lt;strong&gt;Carnivore&lt;/strong&gt; and &lt;strong&gt;Sleepy&lt;/strong&gt;. They’re pure implementation. Clients of &lt;strong&gt;Tiger&lt;/strong&gt; can only see the &lt;strong&gt;Animal&lt;/strong&gt; class and the &lt;strong&gt;IMammal&lt;/strong&gt; interface.&lt;/p&gt;&lt;p&gt;This can be implemented by the compiler with a simple containment:&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; Tiger : Animal, IMammal {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    Carnivore _carnivore = &lt;span&gt;new&lt;/span&gt; Carnivore();&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    Sleepy _sleepy = &lt;span&gt;new&lt;/span&gt; Sleepy();&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Eat() {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        _carnivore.EatMeat();&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Rest() {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        _sleepy.Sleep();&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;We just don’t have to see all the ugliness, and simply use privately inherited classes. In case of name clashes (e.g. an &lt;strong&gt;Eat&lt;/strong&gt; method in &lt;strong&gt;Tiger&lt;/strong&gt; and in &lt;strong&gt;Carnivore&lt;/strong&gt;), we can use an extended syntax such as &lt;strong&gt;Carnivore.Eat()&lt;/strong&gt; to call the method provided by the private inheritance. If the private classes require constructor arguments, they can be provided with the regular constructor like so:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; Tiger() : &lt;span&gt;base&lt;/span&gt;(), Carnivore(10) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;6. More generics features&lt;/h2&gt;&lt;p&gt;Some more features I’d like to see with generics. The first is to provide a default for a generic type:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; MyClass&amp;lt;T = &lt;span&gt;string&lt;/span&gt;&amp;gt; {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This means using &lt;strong&gt;MyClass&amp;lt;&amp;gt;&lt;/strong&gt; (with empty angle brackets would mean using &lt;strong&gt;MyClass&amp;lt;string&amp;gt;&lt;/strong&gt;. This could be implemented using an attribute, much the same as default arguments (from C# 4.0) are specified.&lt;/p&gt;&lt;p&gt;The second feature is specializing for a particular type. For example, we have the &lt;strong&gt;List&amp;lt;T&amp;gt;&lt;/strong&gt; class, but we may want to specialize for specific T, like the following:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; List&amp;lt;&lt;span&gt;bool&lt;/span&gt;&amp;gt; : IList&amp;lt;&lt;span&gt;bool&lt;/span&gt;&amp;gt;, ... {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Set(&lt;span&gt;int&lt;/span&gt; bit) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;//...&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;//...&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This could be used for optimization and/or for expressing a better API (such as the &lt;strong&gt;Set&lt;/strong&gt; method in the above example). The compiler should choose the most specific implementation, only reverting to the “true” generic type if no specific type fits.&lt;/p&gt;&lt;p&gt;Both of these features exist in C++ templates, and I’m certainly not “pushing” towards the template capabilities in C++ – template meta-programming and such is too much for C# and I think it’s inappropriate (and probably impossible to implement in the CLR). However, the above two features can be useful, and should require just slight modifications to the CLR.&lt;/p&gt;&lt;h2&gt;7. Generic attributes&lt;/h2&gt;&lt;p&gt;The last feature I’d like to suggest is generic attributes. Currently, custom attributes cannot be generic, and I see no reason why it should be so. It would be beneficial to write a single attribute that could be used with different types. Here’s an example:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; MyAttribute&amp;lt;T&amp;gt; : Attribute {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; Value { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; T Data { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;[My&amp;lt;&lt;span&gt;string&lt;/span&gt;&amp;gt;(Value = 10, Data = &lt;span&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;class&lt;/span&gt; SomeClass {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The closest we can get today is use a &lt;strong&gt;Type&lt;/strong&gt; constructor parameter, to “force” providing a type, but it’s difficult to get a value for that type (unless object is used).&lt;/p&gt;&lt;h2&gt;8. Add some keywords to LINQ’s query syntax&lt;/h2&gt;&lt;p&gt;I would add take (&lt;a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/bb503062(v=vs.105).aspx" target="_blank"&gt;Take&lt;/a&gt; extension method), &lt;strong&gt;skip&lt;/strong&gt; (&lt;a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/bb358985(v=vs.105).aspx" target="_blank"&gt;Skip&lt;/a&gt;), &lt;strong&gt;union&lt;/strong&gt; (&lt;a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.linq.enumerable.union(v=vs.105).aspx" target="_blank"&gt;Union&lt;/a&gt;), &lt;strong&gt;except&lt;/strong&gt; (&lt;a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.linq.enumerable.except(v=vs.105).aspx" target="_blank"&gt;Except&lt;/a&gt;), &lt;strong&gt;intersect&lt;/strong&gt; (&lt;a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.linq.enumerable.intersect(v=vs.105).aspx" target="_blank"&gt;Intersect&lt;/a&gt;). for example:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;var query = from x &lt;span&gt;in&lt;/span&gt; coll1 union coll2&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;            orderby a&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;            take 10&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;            select a;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;That’s my list for now. We’ll see if any of it comes true.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2119565" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/thoughts/default.aspx">thoughts</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_+3.0/default.aspx">C# 3.0</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_+4.0/default.aspx">C# 4.0</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_+5.0/default.aspx">C# 5.0</category></item><item><title>My Wish List for Windows “Blue”</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/05/17/my-wish-list-for-windows-blue.aspx</link><pubDate>Fri, 17 May 2013 21:48:09 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2044669</guid><dc:creator>pavely</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=2044669</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=2044669</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/05/17/my-wish-list-for-windows-blue.aspx#comments</comments><description>&lt;p&gt;Many rumors are flying around at this time about the upcoming release of Windows 8.1 (code named “Blue”, which represents a wave of product updates, including Windows Phone and others). I thought I‘d state my hopes for this release, not just in terms of user features, but also from a developer’s perspective. As a developer, I spend most of my time on my trusty laptop, not some tablet based device. Naturally, the desktop world is my friend. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;The Windows 8 Start screen is close to perfect for tablet devices, but for the desktop – it’s practically useless. With many programs installed, it’s difficult to find anything in there. I use the excellent search facility of Windows 8 – just press the Windows key and start typing (although I wish all the search results would show&amp;nbsp; - not separated to Apps, Settings and Files). This brings me to the first request – the &lt;strong&gt;Start&lt;/strong&gt; button. Yes, it’s been rehashed quite a bit, but the organization of folders and shortcuts is invaluable and should be back at least on non-tablet devices, but preferably in Windows 8 Pro versions as well, as these devices are often used for development. And no, third party tools and extensions are not an acceptable solution.&lt;/li&gt;&lt;li&gt;Allow running Windows Store apps in a Window, not just full screen – this is also a popular request – and why not? In a tablet world this may be too much – but the desktop? Let me run what I want in whatever size I see fit. There’s really no reason not to allow this. If not that, at least allow more than one app to run concurrently in full screen in different monitors. A pretty typical development setting includes 2 or 3 monitors – I wish we had the freedom to use these as we see fit.&lt;/li&gt;&lt;li&gt;On the actual development front we have WinRT, which is a new platform based on the familiar COM foundation that has various “projections” to languages, such as C++, C# and JavaScript. However, this is only available (at least on the UI side) to Store apps. But why should that be? In the .NET world, there is WPF – arguably the most powerful UI platform on Windows. C++ developers had to use old libraries such as MFC to do their UI – but this model is still limited to the HWND-based Win32 behavior and restrictions. WPF gets rid of HWNDs, which is a major part of its power and flexibility. Now similar power exists for C++ developers but only under WinRT. Why should that be? Let’s have the power of no HWNDs in native code, too. All the required platform components are already there – &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd370990(v=vs.85).aspx" target="_blank"&gt;Direct2D&lt;/a&gt; (which is really how XAML is rendered in WinRT), &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh437371(v=vs.85).aspx" target="_blank"&gt;Direct Composition&lt;/a&gt;, the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee719902(v=vs.85).aspx" target="_blank"&gt;Windows Imaging Component&lt;/a&gt; (WIC), the &lt;a href="http://msdn.microsoft.com/EN-US/library/windows/desktop/dd371981(v=vs.85).aspx" target="_blank"&gt;Windows Animation Manager&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms694197(v=vs.85).aspx" target="_blank"&gt;Windows Media Foundation&lt;/a&gt; and more – it’s just a matter of allowing XAML usage in desktop apps, not just Store apps.&lt;br /&gt;I’ve had customers that have been using &lt;strong&gt;MFC&lt;/strong&gt; for years and exposed to WPF ask me more than once – why is there no WPF-like library in native code? Indeed, why? I remember in the beta days of WPF (then called “Avalon”), I searched the MSDN docs relentlessly, trying to find the native library that Avalon wraps. I was eventually astonished to find that there is none. WPF is a managed only library. But now, after all the WinRT work as been done, what’s stopping it from migrating to the desktop apps world? Nothing, in my humble opinion, and I wish that would happen. With the new C++11 features, a powerful native UI framework is sorely missing.&lt;/li&gt;&lt;li&gt;WinRT is based on ideas starting from WPF, but it’s a lot less powerful. It’s about as powerful as Silverlight 3. Yes, 3; not even 4, not to mention 5. I understand there was a lot of work involved in getting WinRT out there, so not all features could be implemented. I hope more features appear in Windows 8.1, comparable at least to Silverlight 5. I don’t expect the entire WPF library to be implemented, and in fact, some things are better off not being there, but I think it should get close. It’s frustrating working with WPF and then going over to WinRT only to find a lot of things missing.&lt;/li&gt;&lt;li&gt;Open up Windows Phone some more – Windows Phone 8 is certainly more “open” that Windows Phone 7.x. But it’s still pretty closed. One argument for that is the assurance that apps could not exploit the user’s information or device for malicious purposes. Sure, there is that risk. But that what capabilities are for. There is a capability for location awareness, for instance, so the user must consent to the app being installed on his phone (from the Store) based on the app’s advertised capabilities and requirements. I say – add more capabilities, but allow more freedom for phone usage. &lt;/li&gt;&lt;li&gt;While we’re on the phone’s subject – let’s have a window or an app that summarizes the things that have changed while the phone was unattended. Missed calls, messages, tweets, Voip calls, whatever – all in one easy to find list – not scattered around among the various apps as it is today. &lt;br /&gt;There are other small features I can think of regarding the phone, but this one stands out; I won’t discuss the rest here.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;There are more things I wish for the Windows OS – but I think that’s enough for the upcoming release. We’ll have to wait and see how much of it (if any) comes true.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2044669" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/MFC/default.aspx">MFC</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/COM/default.aspx">COM</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DirectX/default.aspx">DirectX</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Media+Foundation/default.aspx">Media Foundation</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+8/default.aspx">Windows 8</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+Runtime/default.aspx">Windows Runtime</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2B002B002F00_CX/default.aspx">C++/CX</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/Windows+Phone+8/default.aspx">Windows Phone 8</category></item><item><title>XAML as DSL</title><link>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/05/05/xaml-as-dsl.aspx</link><pubDate>Sun, 05 May 2013 20:14:34 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1998112</guid><dc:creator>pavely</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/rsscomments.aspx?PostID=1998112</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/pavely/commentapi.aspx?PostID=1998112</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/pavely/archive/2013/05/05/xaml-as-dsl.aspx#comments</comments><description>&lt;p&gt;About 3 years ago, when .NET 4 and Visual Studio 2010 were just released, I’ve blogged (part 1, part 2) about the changes that took XAML from its WPF inception to the &lt;a href="http://msdn.microsoft.com/EN-US/library/dd295048(v=VS.110,d=hv.2).aspx" target="_blank"&gt;System.Xaml&lt;/a&gt; namespace and &lt;strong&gt;System.Xaml.Dll&lt;/strong&gt; assembly, to be available more generally, not just for WPF. I’ve shown that XAML is just a declarative way of creating objects, setting their properties – sometimes in interesting ways. I did promise at the end of that second post that I’d show how to use attached properties, but never did have the time to deliver. 3 years later, it’s high time I make good on that promise.&lt;/p&gt;&lt;p&gt;The idea of a &lt;a href="http://en.wikipedia.org/wiki/Domain-specific_language" target="_blank"&gt;Domain Specific Language&lt;/a&gt; (DSL) is not new. Probably the most well known DSL is SQL – a language for working with databases. A DSL is typically constrained to a specific domain or a specific task (hence the name). A DSL may be a completely new language (such as SQL), and this is termed “external DSL”, and it can be constructed using a specific language semantics, such as C#, by leveraging certain language features that make up the “new” language. in C#, extension methods and “fluent interfaces” are most often used for that task.&lt;/p&gt;&lt;p&gt;What about XAML? The declarative nature of XAML makes it a good candidate to be a DSL. It has simple and strict rules, but it allows extensions, with type converters, markup extensions and attached properties.&lt;/p&gt;&lt;h2&gt;An example&lt;/h2&gt;&lt;p&gt;Suppose we want to create a &lt;a href="http://en.wikipedia.org/wiki/Text_adventure" target="_blank"&gt;text adventure game&lt;/a&gt; (“interactive fiction”) language (yes, I know I have a fetish for text adventures…). We could use XAML to describe not just the world that comprises the game, but also the actions that need to take place in certain scenarios.&lt;/p&gt;&lt;p&gt;The first step is to create an object model suitable to describe a text adventure. Here are a few simple classes to get us started:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:10pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:10pt;direction:ltr;background-color:white;"&gt;[Serializable]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;[DictionaryKeyProperty(&lt;span&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:10pt;direction:ltr;background-color:white;"&gt;[DebuggerDisplay(&lt;span&gt;&amp;quot;{Name}&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;abstract&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; Entity {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:10pt;direction:ltr;background-color:white;"&gt;    Dictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, &lt;span&gt;object&lt;/span&gt;&amp;gt; _properties;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:10pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; IDictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, &lt;span&gt;object&lt;/span&gt;&amp;gt; Properties {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:10pt;direction:ltr;background-color:white;"&gt;        get {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;            &lt;span&gt;return&lt;/span&gt; _properties ?? (_properties = &lt;span&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, &lt;span&gt;object&lt;/span&gt;&amp;gt;(4, StringComparer.CurrentCultureIgnoreCase));&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:10pt;direction:ltr;background-color:white;"&gt;        }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:10pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;enum&lt;/span&gt; RelativeLocation {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    In, On, Under, Behind&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;[Serializable]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;[DebuggerDisplay(&lt;span&gt;&amp;quot;{Name} ({GetType().Name}) {RelativeLocation} {Location}&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;abstract&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; Thing : Entity {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; Thing() {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        Article = &lt;span&gt;&amp;quot;a&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        Count = 1;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; Location { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; RelativeLocation RelativeLocation { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    [TypeConverter(&lt;span&gt;typeof&lt;/span&gt;(StringListConverter))]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt;[] Nouns { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    [TypeConverter(&lt;span&gt;typeof&lt;/span&gt;(StringListConverter))]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt;[] Adjectives { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; Article { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;bool&lt;/span&gt; IsTransparent { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; Weight { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; Size { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; ShortDesc { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; LongDesc { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;[Serializable]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; Item : Thing {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; Item() {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        CanTake = &lt;span&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;bool&lt;/span&gt; IsOpen { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;bool&lt;/span&gt; CanOpen { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;bool&lt;/span&gt; IsContainer { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;bool&lt;/span&gt; IsLocked { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; Key { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;bool&lt;/span&gt; CanLock { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;bool&lt;/span&gt; CanTake { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;A few interesting things here:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;1. The &lt;a href="http://msdn.microsoft.com/EN-US/library/vstudio/system.windows.markup.dictionarykeypropertyattribute(v=vs.100).aspx" target="_blank"&gt;DictionaryKeyProperty&lt;/a&gt; attribute indicates which property should be considered a key, should such an object be placed in a dictionary. This will allow us to avoid using the more awkward and generic &lt;strong&gt;x:Key&lt;/strong&gt; XAML attribute.&lt;/li&gt;&lt;li&gt;2. The &lt;a href="http://msdn.microsoft.com/EN-US/library/s5bse4c4(v=VS.110,d=hv.2).aspx" target="_blank"&gt;TypeConverter&lt;/a&gt; attribute indicates how a string is to be converted to a more complex type, such as the &lt;strong&gt;Nouns&lt;/strong&gt; property:&lt;/li&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;[TypeConverter(&lt;span&gt;typeof&lt;/span&gt;(StringListConverter))]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt;[] Nouns { get; set; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/ul&gt;&lt;p&gt;This particular converter turns a string into an array of strings. Here’s the implementation:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; StringListConverter : TypeConverter {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;override&lt;/span&gt; &lt;span&gt;object&lt;/span&gt; ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, &lt;span&gt;object&lt;/span&gt; &lt;span&gt;value&lt;/span&gt;) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        var target = context &lt;span&gt;as&lt;/span&gt; IProvideValueTarget;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        Type type = &lt;span&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;if&lt;/span&gt;(target != &lt;span&gt;null&lt;/span&gt;) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;            type = (target.TargetProperty &lt;span&gt;as&lt;/span&gt; PropertyInfo).PropertyType;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;string&lt;/span&gt; svalue = (&lt;span&gt;string&lt;/span&gt;)&lt;span&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        var words = svalue.Split(&lt;span&gt;new&lt;/span&gt; [] {&lt;span&gt;&amp;#39;,&amp;#39;&lt;/span&gt;}, StringSplitOptions.RemoveEmptyEntries);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;return&lt;/span&gt; type == &lt;span&gt;typeof&lt;/span&gt;(&lt;span&gt;string&lt;/span&gt;[]) ? (&lt;span&gt;object&lt;/span&gt;)words : words.ToList();&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;override&lt;/span&gt; &lt;span&gt;bool&lt;/span&gt; CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;return&lt;/span&gt; sourceType == &lt;span&gt;typeof&lt;/span&gt;(&lt;span&gt;string&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The code can actually convert to an array of strings or a list of strings (it looks for a comma as a separator to split the words). Converters is one of those things that make XAML friendly, readable and easy to use.&lt;/p&gt;&lt;p&gt;Let’s take a look at something more interesting: markup extensions. Suppose we want to be able to place items in rooms or other containers. For example, a ring may be in the bedroom, or on the table, or in a box. We want to be able to “say” that as easily as possible (we are striving for a DSL). Here’s some XAML that accomplishes this:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Item&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;ring&amp;quot;&lt;/span&gt; &lt;span&gt;Location&lt;/span&gt;&lt;span&gt;=&amp;quot;{In box}&amp;quot;&lt;/span&gt; &lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;Nouns&lt;/span&gt;&lt;span&gt;=&amp;quot;ring&amp;quot;&lt;/span&gt; &lt;span&gt;Adjectives&lt;/span&gt;&lt;span&gt;=&amp;quot;small,diamond&amp;quot;&lt;/span&gt; &lt;span&gt;Article&lt;/span&gt;&lt;span&gt;=&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Item&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Item&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;box&amp;quot;&lt;/span&gt; &lt;span&gt;Location&lt;/span&gt;&lt;span&gt;=&amp;quot;kitchen&amp;quot;&lt;/span&gt; &lt;span&gt;Nouns&lt;/span&gt;&lt;span&gt;=&amp;quot;box&amp;quot;&lt;/span&gt; &lt;span&gt;IsOpen&lt;/span&gt;&lt;span&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Item&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Room&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;kitchen&amp;quot;&lt;/span&gt; &lt;span&gt;Attributes&lt;/span&gt;&lt;span&gt;=&amp;quot;Cold,Dark&amp;quot;&lt;/span&gt; &lt;span&gt;ShortDesc&lt;/span&gt;&lt;span&gt;=&amp;quot;A small kitchen&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Room&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Note the&lt;strong&gt; {In box}&lt;/strong&gt; location of the ring. To make that work, there must be a class named &lt;strong&gt;In&lt;/strong&gt; or &lt;strong&gt;InExtension&lt;/strong&gt; that accepts a string as a constructor argument. In fact, we can create a bunch of those like so:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;abstract&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; RelativeLocationExtension : MarkupExtension {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; RelativeLocation RelativeLocation { get; &lt;span&gt;private&lt;/span&gt; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; Name { get; &lt;span&gt;private&lt;/span&gt; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;protected&lt;/span&gt; RelativeLocationExtension(RelativeLocation rl, &lt;span&gt;string&lt;/span&gt; name) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        RelativeLocation = rl;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        Name = name;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;override&lt;/span&gt; &lt;span&gt;object&lt;/span&gt; ProvideValue(IServiceProvider sp) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        var target = sp.GetService(&lt;span&gt;typeof&lt;/span&gt;(IProvideValueTarget)) &lt;span&gt;as&lt;/span&gt; IProvideValueTarget;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;if&lt;/span&gt;(target != &lt;span&gt;null&lt;/span&gt;) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;            &lt;span&gt;if&lt;/span&gt;(target.TargetObject.GetType().IsSubclassOf(&lt;span&gt;typeof&lt;/span&gt;(Thing))) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                target.TargetObject.GetType().GetProperty(&lt;span&gt;&amp;quot;RelativeLocation&amp;quot;&lt;/span&gt;).SetValue(target.TargetObject, RelativeLocation);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;            }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;            &lt;span&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                &lt;span&gt;throw&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; ArgumentException(&lt;span&gt;&amp;quot;object must be a thing for a location&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;return&lt;/span&gt; Name;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; OnExtension : RelativeLocationExtension {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; OnExtension(&lt;span&gt;string&lt;/span&gt; name) : &lt;span&gt;base&lt;/span&gt;(RelativeLocation.On, name) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; InExtension : RelativeLocationExtension {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; InExtension(&lt;span&gt;string&lt;/span&gt; name)&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        : &lt;span&gt;base&lt;/span&gt;(RelativeLocation.In, name) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; UnderExtension : RelativeLocationExtension {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; UnderExtension(&lt;span&gt;string&lt;/span&gt; name) : &lt;span&gt;base&lt;/span&gt;(RelativeLocation.Under, name) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Any markup extension must implement the &lt;a href="http://msdn.microsoft.com/EN-US/library/ms590291(v=VS.110,d=hv.2).aspx" target="_blank"&gt;ProvideValue&lt;/a&gt; method. The provided &lt;a href="http://msdn.microsoft.com/EN-US/library/system.iserviceprovider.aspx" target="_blank"&gt;IServiceProvider&lt;/a&gt; can be used to get the context in which the markup extension is used. The &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.iprovidevaluetarget.aspx" target="_blank"&gt;IProvideValueTarget&lt;/a&gt; interface is the most common and useful to use. It lets the code know on which object and which property is set with the markup extension. Markup extensions provide a powerful extensibility mechanism that’s still easy to use by our DSL.&lt;/p&gt;&lt;h2&gt;Attached properties&lt;/h2&gt;&lt;p&gt;WPF invented attached properties, now used in other XAML based technologies. Attached properties are defined by one type but can be set on any object. They are “attached” to objects, providing the idea of context properties. By the way, they don’t have to be dependency properties (as in WPF/Silverlight) in any way. Their implementation is irrelevant to the XAML parser.&lt;/p&gt;&lt;p&gt;In fact, to parse attached properties, the XAML parser requires the defining class to have a static &lt;strong&gt;GetXxx&lt;/strong&gt; and/or &lt;strong&gt;SetXxx&lt;/strong&gt; for the attached property Xxx. In the implementation, we need to store/retrieve the value of the property from some attached property store – conceptually similar to the way WPF manages an attached property – by using some global static variable.&lt;/p&gt;&lt;p&gt;Technically, that store needs to implement the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xaml.iattachedpropertystore.aspx" target="_blank"&gt;IAttachedPropertyStore&lt;/a&gt; interface. Although it’s not difficult to implement (most use a dictionary), .NET provides a default implementation accessible with the convenient &lt;a href="http://msdn.microsoft.com/EN-US/library/dd414241(v=VS.110,d=hv.2).aspx" target="_blank"&gt;AttachablePropertyServices&lt;/a&gt; static class. Here’s an example of creating an attached property named &lt;strong&gt;Commands.Script&lt;/strong&gt; (in this case read only):&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; Commands {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; IList&amp;lt;ScriptCommand&amp;gt; GetScript(Entity entity) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        IList&amp;lt;ScriptCommand&amp;gt; &lt;span&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        AttachablePropertyServices.TryGetProperty&amp;lt;IList&amp;lt;ScriptCommand&amp;gt;&amp;gt;(entity, &lt;span&gt;new&lt;/span&gt; AttachableMemberIdentifier(&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;            &lt;span&gt;typeof&lt;/span&gt;(Commands), &lt;span&gt;&amp;quot;Script&amp;quot;&lt;/span&gt;), &lt;span&gt;out&lt;/span&gt; &lt;span&gt;value&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;if&lt;/span&gt;(&lt;span&gt;value&lt;/span&gt; == &lt;span&gt;null&lt;/span&gt;) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;            &lt;span&gt;value&lt;/span&gt; = &lt;span&gt;new&lt;/span&gt; List&amp;lt;ScriptCommand&amp;gt;();&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;            AttachablePropertyServices.SetProperty(entity, &lt;span&gt;new&lt;/span&gt; AttachableMemberIdentifier(&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                &lt;span&gt;typeof&lt;/span&gt;(Commands), &lt;span&gt;&amp;quot;Script&amp;quot;&lt;/span&gt;), &lt;span&gt;value&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Now we can use the property like so (for a Room in this example):&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Room&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;kitchen&amp;quot;&lt;/span&gt; &lt;span&gt;Attributes&lt;/span&gt;&lt;span&gt;=&amp;quot;Cold,Dark&amp;quot;&lt;/span&gt; &lt;span&gt;ShortDesc&lt;/span&gt;&lt;span&gt;=&amp;quot;A small kitchen&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;  &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Commands.Script&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt; &lt;span&gt;Verb&lt;/span&gt;&lt;span&gt;=&amp;quot;smell&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;      &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt; &lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&amp;quot;You smell hot peppers eveywhere.&amp;quot;&lt;/span&gt; &lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt; &lt;span&gt;Verb&lt;/span&gt;&lt;span&gt;=&amp;quot;listen&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;      &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;You hear nothing special.&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;  &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Commands.Script&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Room&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;ScriptCommand&lt;/strong&gt; and &lt;strong&gt;Print&lt;/strong&gt; are some other classes that are part of the object model for the game.&lt;/p&gt;&lt;h2&gt;From XAML to Objects&lt;/h2&gt;&lt;p&gt;Here’s some part of a complete XAML we may wish to parse:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;GameFile&lt;/span&gt; &lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;=&amp;quot;http://xamlventure/2013&amp;quot;&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;  &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;GameFile.Resources&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Variable&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;light carried&amp;quot;&lt;/span&gt; &lt;span&gt;Value&lt;/span&gt;&lt;span&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;CanMoveToCondition&lt;/span&gt; &lt;span&gt;Direction&lt;/span&gt;&lt;span&gt;=&amp;quot;North&amp;quot;&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;canMoveNorth&amp;quot;&lt;/span&gt; &lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;  &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;GameFile.Resources&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Item&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;ring&amp;quot;&lt;/span&gt; &lt;span&gt;Location&lt;/span&gt;&lt;span&gt;=&amp;quot;{In box}&amp;quot;&lt;/span&gt; &lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;            &lt;span&gt;Nouns&lt;/span&gt;&lt;span&gt;=&amp;quot;ring&amp;quot;&lt;/span&gt; &lt;span&gt;Adjectives&lt;/span&gt;&lt;span&gt;=&amp;quot;small,diamond&amp;quot;&lt;/span&gt; &lt;span&gt;Article&lt;/span&gt;&lt;span&gt;=&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Commands.Script&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;      &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt; &lt;span&gt;Verb&lt;/span&gt;&lt;span&gt;=&amp;quot;take&amp;quot;&lt;/span&gt; &lt;span&gt;DirectObject&lt;/span&gt;&lt;span&gt;=&amp;quot;ring&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt; &lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&amp;quot;Your hand is stopped by an invisible shield around the ring.&amp;quot;&lt;/span&gt; &lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;            &lt;span&gt;Condition&lt;/span&gt;&lt;span&gt;=&amp;quot;{Property Glowing, Object=ring, Value=True}&amp;quot;&lt;/span&gt; &lt;span&gt;Continue&lt;/span&gt;&lt;span&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;The ring shines momentarily as you grab it in your hand.&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;PausePrint&lt;/span&gt; &lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;      &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Commands.Script&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Item&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;  &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Item&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;box&amp;quot;&lt;/span&gt; &lt;span&gt;Location&lt;/span&gt;&lt;span&gt;=&amp;quot;kitchen&amp;quot;&lt;/span&gt; &lt;span&gt;Nouns&lt;/span&gt;&lt;span&gt;=&amp;quot;box&amp;quot;&lt;/span&gt; &lt;span&gt;IsOpen&lt;/span&gt;&lt;span&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;  &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Item&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;  &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Room&lt;/span&gt; &lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&amp;quot;kitchen&amp;quot;&lt;/span&gt; &lt;span&gt;Attributes&lt;/span&gt;&lt;span&gt;=&amp;quot;Cold,Dark&amp;quot;&lt;/span&gt; &lt;span&gt;ShortDesc&lt;/span&gt;&lt;span&gt;=&amp;quot;A small kitchen&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Commands.Script&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;      &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt; &lt;span&gt;Verb&lt;/span&gt;&lt;span&gt;=&amp;quot;smell&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt; &lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&amp;quot;You smell hot peppers eveywhere.&amp;quot;&lt;/span&gt; &lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;      &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;      &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt; &lt;span&gt;Verb&lt;/span&gt;&lt;span&gt;=&amp;quot;listen&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        &lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;You hear nothing special.&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Print&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;      &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;ScriptCommand&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Commands.Script&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;  &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Room&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The XAML uses other classes not described above, with some other markup extensions, such as {Property} and {Condition}.&lt;/p&gt;&lt;p&gt;Note the XML namespace at the top of the file. This defines the relationship between XAML types and .NET types. The .NET types may be spread across multiple .NET namespaces, but the XML namespace maps to all of those. This is done using the following attributes:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;[assembly: XmlnsDefinition(&lt;span&gt;&amp;quot;http://xamlventure/2013&amp;quot;&lt;/span&gt;, &lt;span&gt;&amp;quot;XamlVenture.ObjectModel&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;[assembly: XmlnsDefinition(&lt;span&gt;&amp;quot;http://xamlventure/2013&amp;quot;&lt;/span&gt;, &lt;span&gt;&amp;quot;XamlVenture.ObjectModel.MarkupExtensions&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;[assembly: XmlnsDefinition(&lt;span&gt;&amp;quot;http://xamlventure/2013&amp;quot;&lt;/span&gt;, &lt;span&gt;&amp;quot;XamlVenture.ObjectModel.Actions&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;[assembly: XmlnsDefinition(&lt;span&gt;&amp;quot;http://xamlventure/2013&amp;quot;&lt;/span&gt;, &lt;span&gt;&amp;quot;XamlVenture.ObjectModel.Conditions&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This is easier than the alternative XAML namespace mapping (this is the way WPF/Silverlight works to get the correct mappings).&lt;/p&gt;&lt;p&gt;The next step is to turn the XAML into the &lt;strong&gt;GameFile&lt;/strong&gt; root object with everything inside. The simplest way to do this is with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xaml.xamlservices.aspx" target="_blank"&gt;XamlServices&lt;/a&gt; class:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;var root = (GameFile)XamlServices.Load(path);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This returns the root &lt;strong&gt;GameFile&lt;/strong&gt; object and everything else inside it. &lt;strong&gt;GameFile&lt;/strong&gt; is defined like so (partial):&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;[Serializable]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;[ContentProperty(&lt;span&gt;&amp;quot;Entities&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;sealed&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; GameFile {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    [DebuggerBrowsable(DebuggerBrowsableState.Never)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    Dictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Entity&amp;gt; _entities = &lt;span&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Entity&amp;gt;(32, StringComparer.CurrentCultureIgnoreCase);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    [DebuggerBrowsable(DebuggerBrowsableState.Never)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    Dictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Verb&amp;gt; _verbs = &lt;span&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Verb&amp;gt;(8, StringComparer.CurrentCultureIgnoreCase);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    [DebuggerBrowsable(DebuggerBrowsableState.Never)]&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    Dictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Resource&amp;gt; _resources;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; IDictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Entity&amp;gt; Entities {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        get { &lt;span&gt;return&lt;/span&gt; _entities; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; IDictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Verb&amp;gt; Verbs {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        get { &lt;span&gt;return&lt;/span&gt; _verbs; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; IDictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Resource&amp;gt; Resources {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        get {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;             &lt;span&gt;if&lt;/span&gt;(_resources == &lt;span&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                _resources = &lt;span&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span&gt;string&lt;/span&gt;, Resource&amp;gt;(4, StringComparer.InvariantCultureIgnoreCase);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;            &lt;span&gt;return&lt;/span&gt; _resources; &lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;        }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;    &lt;span&gt;public&lt;/span&gt; Game Game { get; set; }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.contentpropertyattribute.aspx" target="_blank"&gt;ContentProperty&lt;/a&gt; attribute is another common helper that sets the “default” property for the particular type.&lt;/p&gt;&lt;p&gt;If more control is required during parsing, such as running some extra initialization after or during certain object creation, a more elaborate parsing loop can be created:&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="margin:20px 0px 10px;padding:4px;border:1px solid silver;width:97.5%;text-align:left;line-height:12pt;overflow:auto;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;font-size:8pt;cursor:text;direction:ltr;max-height:200px;"&gt;&lt;div id="codeSnippet" style="padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;
&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&lt;span&gt;using&lt;/span&gt;(var reader = &lt;span&gt;new&lt;/span&gt; XamlXmlReader(path)) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    &lt;span&gt;using&lt;/span&gt;(var writer = &lt;span&gt;new&lt;/span&gt; XamlObjectWriter(&lt;span&gt;new&lt;/span&gt; XamlSchemaContext())) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        &lt;span&gt;while&lt;/span&gt;(reader.Read()) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;            &lt;span&gt;switch&lt;/span&gt;(reader.NodeType) {&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                &lt;span&gt;case&lt;/span&gt; XamlNodeType.StartObject:&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                    writer.WriteNode(reader);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                    &lt;span&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                &lt;span&gt;case&lt;/span&gt; XamlNodeType.StartMember:&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                    &lt;span&gt;goto&lt;/span&gt; &lt;span&gt;default&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                &lt;span&gt;case&lt;/span&gt; XamlNodeType.EndObject:&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                    writer.WriteNode(reader);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                    AnalyzeObject(writer.Result);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                    &lt;span&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                &lt;span&gt;default&lt;/span&gt;:&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;                    writer.WriteNode(reader);&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;                    &lt;span&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;            }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;        }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;"&gt;    }&lt;/pre&gt;&lt;pre style="margin:0em;padding:0px;width:100%;text-align:left;color:black;line-height:12pt;overflow:visible;font-family:&amp;#39;Consolas&amp;#39;, courier, monospace;font-size:11pt;direction:ltr;background-color:white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;After each XAML token is read, the code can do something with it. The most useful node type is &lt;strong&gt;EndObject&lt;/strong&gt;, indicating a complete object has been written. This is a perfect opportunity to do something with that object, such as create extra objects based on its state, set some other properties or anything else that’s required. (the &lt;strong&gt;AnalyzeObject&lt;/strong&gt; dummy method above indicates such operations).&lt;/p&gt;&lt;p&gt;After the parsing is complete, the resulting object model can be transformed to another form or another object model if needed; or it can just be used as is in the target application.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;XAML is an effective DSL; being XAML – and XML – makes it easy to work with – as a developer and as a user, as there are many ways to simplify XML input.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1998112" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/PARSING/default.aspx">PARSING</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.microsoft.co.il/blogs/pavely/archive/tags/.NET+4.5/default.aspx">.NET 4.5</category></item></channel></rss>