<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Kirill Osenkov</title><link>http://blogs.msdn.com/kirillosenkov/default.aspx</link><description>Visual Studio C# IDE QA team member</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Visual Studio 2010 Beta 2 Known Issues – Part 2</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/11/12/visual-studio-2010-beta-2-known-issues-part-2.aspx</link><pubDate>Thu, 12 Nov 2009 09:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9921253</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9921253.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9921253</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9921253</wfw:comment><description>&lt;P&gt;This post continues my unofficial list of known issues in VS 2010 Beta 2 (&lt;A href="http://blogs.msdn.com/kirillosenkov/archive/2009/10/19/visual-studio-2010-beta-2-known-issues.aspx" mce_href="http://blogs.msdn.com/kirillosenkov/archive/2009/10/19/visual-studio-2010-beta-2-known-issues.aspx"&gt;see Part 1&lt;/A&gt;). As we continue getting Beta 2 feedback and investigating issues, it's time for another update on the issues we've been seeing. Please keep in mind that due to the volume of the issues, I'm only mentioning the ones I was involved with or consider important.&lt;/P&gt;
&lt;H3&gt;Crash during normal editor operation&lt;/H3&gt;
&lt;P&gt;There is a rare situation where Beta 2 can crash during normal editing or viewing C# source code. Nevertheless, it happens often enough to become top 1 reported crash for C#.&lt;/P&gt;
&lt;P&gt;I'm very happy to say that we have identified the root cause and are working on a fix.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Details:&lt;/STRONG&gt; This is an extremely complex and hard to reproduce bug involving native code, threading, and working with Task Parallel Library from native code. The new C# IDE feature, Highlight References, is written in managed code and uses TPL (&lt;A href="http://msdn.microsoft.com/en-us/magazine/cc163340.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc163340.aspx"&gt;Task Parallel Library&lt;/A&gt;) to calculate references on a threadpool thread. However a certain portion of the language service (called the Language Analysis engine) is written in native code, so we had to do some cross-boundary and cross-thread manupulation. Our developers &lt;A href="http://blogs.msdn.com/ianhalliday/" mce_href="http://blogs.msdn.com/ianhalliday/"&gt;Ian&lt;/A&gt; (from C# compiler) and &lt;A href="http://blogs.msdn.com/heejaechang/" mce_href="http://blogs.msdn.com/heejaechang/"&gt;HeeJae&lt;/A&gt; (from C# IDE) worked very very hard to investigate the dumps that you folks were sending in and finally they've found the bug. The good news is that as more and more of Visual Studio gets rewritten in managed code, we hope to see less of such bad bugs in the future.&lt;/P&gt;
&lt;P&gt;So thanks to you for clicking that "Send Error Report" button – it really helped us to fix the top 1 reported C# crash!&lt;/P&gt;
&lt;H3&gt;Cannot open C# source file: Error message "The operation could not be completed. Invalid pointer." or "Object reference not set to an instance of an object"&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A title=http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=505257 href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=505257" mce_href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=505257"&gt;http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=505257&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=499263" mce_href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=499263"&gt;http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=499263&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=505531" mce_href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=505531"&gt;http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=505531&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=499803" mce_href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=499803"&gt;http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=499803&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;This one is due to the Tools Options Fonts and Colors using a raster font instead of a TrueType font: &lt;/P&gt;
&lt;P&gt;&lt;A title=http://blogs.msdn.com/visualstudio/archive/2009/10/27/VS-2010-Beta2_3A00_--Workaround-for-Raster-Font-Settings-Issue.aspx href="http://blogs.msdn.com/visualstudio/archive/2009/10/27/VS-2010-Beta2_3A00_--Workaround-for-Raster-Font-Settings-Issue.aspx" mce_href="http://blogs.msdn.com/visualstudio/archive/2009/10/27/VS-2010-Beta2_3A00_--Workaround-for-Raster-Font-Settings-Issue.aspx"&gt;http://blogs.msdn.com/visualstudio/archive/2009/10/27/VS-2010-Beta2_3A00_--Workaround-for-Raster-Font-Settings-Issue.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The fix is easy: switch to a TrueType font such as Consolas or Courier New.&lt;/P&gt;
&lt;P&gt;The editor team has fixed this one already.&lt;/P&gt;
&lt;H3&gt;The application cannot start (VS black screen)&lt;/H3&gt;
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/blogfiles/charlie/WindowsLiveWriter/TwoIssueswithVisualStudio2010Beta2TheApp_D481/ApplicationCannotStart_2.png" mce_src="http://blogs.msdn.com/blogfiles/charlie/WindowsLiveWriter/TwoIssueswithVisualStudio2010Beta2TheApp_D481/ApplicationCannotStart_2.png"&gt;&lt;/P&gt;
&lt;P&gt;Weston writes about this one in detail: &lt;A title=http://blogs.msdn.com/visualstudio/archive/2009/10/29/how-to-fix-the-application-cannot-start-error.aspx href="http://blogs.msdn.com/visualstudio/archive/2009/10/29/how-to-fix-the-application-cannot-start-error.aspx" mce_href="http://blogs.msdn.com/visualstudio/archive/2009/10/29/how-to-fix-the-application-cannot-start-error.aspx"&gt;http://blogs.msdn.com/visualstudio/archive/2009/10/29/how-to-fix-the-application-cannot-start-error.aspx&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is due to us being unable to read certain profile settings.&lt;/P&gt;
&lt;P&gt;The workaround is basically to run devenv /resetuserdata from the Visual Studio command prompt, but I encourage you to follow the link above for more information (e.g. how to save your settings beforehand).&lt;/P&gt;
&lt;P&gt;This is already fixed as well (now even if the profile contains the errors we will start successfully and deal with the errors).&lt;/P&gt;
&lt;H3&gt;TextOptions does not appear in the IntelliSense in XAML designer&lt;/H3&gt;
&lt;P&gt;The WPF team has &lt;A href="http://blogs.msdn.com/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx" mce_href="http://blogs.msdn.com/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx"&gt;completely rewritten the WPF text rendering&lt;/A&gt; to get rid of the font blurryness issue. The old style is still the default, to enable the new mode you need this simple attribute in your XAML: TextOptions.TextFormattingMode="Display". The problem is – TextOptions won't show up in IntelliSense!&lt;/P&gt;
&lt;P&gt;The workaround is to ignore IntelliSense and just build your project – things should just work.&lt;/P&gt;
&lt;P&gt;This has been fixed as well.&lt;/P&gt;
&lt;H3&gt;All menus except the File menu disappear&lt;/H3&gt;
&lt;P&gt;It happens extremely rarely, but we saw it three times already – the menus are just gone!&lt;/P&gt;
&lt;P&gt;&lt;A href="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image.png" mce_href="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_thumb.png" width=352 height=94 mce_src="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;This one is very very hard to reproduce and we're still investigating this right now – for some unknown reason something is messing up the Style or the ControlTemplate for the menus. If you happen to run into this inside a virtual machine, you can really help us investigate the issue by pausing the machine in the state where VS is running and menus are gone.&lt;/P&gt;
&lt;P&gt;Feel free to open a bug on &lt;A href="http://connect.microsoft.com/visualstudio/feedback" mce_href="http://connect.microsoft.com/visualstudio/feedback"&gt;http://connect.microsoft.com/visualstudio/feedback&lt;/A&gt; or let me know and we'll send you instructions on how to upload the VM image.&lt;/P&gt;
&lt;H3&gt;Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.Editor.Implementation.IVsGlobalUndoCapableUndoManager'.&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=501319" mce_href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=501319"&gt;http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=501319&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=498787" mce_href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=498787"&gt;http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=498787&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;---------------------------&lt;/P&gt;
&lt;P&gt;Microsoft Visual Studio&lt;/P&gt;
&lt;P&gt;---------------------------&lt;/P&gt;
&lt;P&gt;Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.Editor.Implementation.IVsGlobalUndoCapableUndoManager'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{305E8709-55B7-4732-B872-1C073AB58047}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).&lt;/P&gt;
&lt;P&gt;---------------------------&lt;/P&gt;
&lt;P&gt;OK &lt;/P&gt;
&lt;P&gt;---------------------------&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Right now we can't reproduce it so we're looking for any help – call stack, minidump with heap, ActivityLog.xml etc. You can read more about the ActivityLog here: &lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms241272.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms241272.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms241272.aspx&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;We'd appreciate any help!&lt;/P&gt;
&lt;H3&gt;Expression.Compile generates incorrect code for (int?) conversion&lt;/H3&gt;&lt;PRE style="FONT-FAMILY: consolas, font-size: 3" class=code&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Linq.Expressions;

&lt;SPAN style="COLOR: blue"&gt;class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Program
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;static void &lt;/SPAN&gt;Main()
    {
        &lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ValueType&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;?&amp;gt;&amp;gt; expr = x =&amp;gt; (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;?)x;
        &lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ValueType&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;?&amp;gt; converter1 = x =&amp;gt; (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;?)x;
        &lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ValueType&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;?&amp;gt; converter2 = expr.Compile();

        &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;? a1 = converter1(&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;); &lt;SPAN style="COLOR: green"&gt;// (int?) null
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;? a2 = converter2(&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;); &lt;SPAN style="COLOR: green"&gt;// NRE
    &lt;/SPAN&gt;}
}&lt;/PRE&gt;
&lt;P&gt;Expected: both the direct delegate and the one generated with Expression Trees should work identically. Actual: the expression tree one throws a NullReferenceException.&lt;/P&gt;
&lt;P&gt;Thanks to &lt;A href="http://twitter.com/controlflow" mce_href="http://twitter.com/controlflow"&gt;controlflow&lt;/A&gt; for reporting this! It's a good bug, but unfortunately it will require a risky compiler change that we don't want to take so late in the product cycle. We've postponed the bug for a later release.&lt;/P&gt;
&lt;H3&gt;Delegate.Combine doesn't support variance&lt;/H3&gt;&lt;PRE style="FONT-FAMILY: consolas, font-size: 3" class=code&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System;

&lt;SPAN style="COLOR: blue"&gt;class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;A &lt;/SPAN&gt;{ }
&lt;SPAN style="COLOR: blue"&gt;class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;B &lt;/SPAN&gt;: &lt;SPAN style="COLOR: #2b91af"&gt;A &lt;/SPAN&gt;{ }

&lt;SPAN style="COLOR: blue"&gt;class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Program
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;static void &lt;/SPAN&gt;Main()
    {
        &lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;B&lt;/SPAN&gt;&amp;gt; b = _ =&amp;gt; { };
        &lt;SPAN style="COLOR: #2b91af"&gt;Action&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;A&lt;/SPAN&gt;&amp;gt; a = _ =&amp;gt; { };
        b += a;
    }
}&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program compiles fine but causes an exception at runtime. The CLR team decided to postpone this to a future version.&lt;/P&gt;
&lt;H3&gt;Completion List doesn't show up for certain lambda parameters in multiple overload scenarios&lt;/H3&gt;&lt;PRE style="FONT-FAMILY: consolas, font-size: 3" class=code&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System;

&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Linq;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Threading.Tasks;

&lt;SPAN style="COLOR: blue"&gt;class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Program
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;static void &lt;/SPAN&gt;Main(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;[] args)
    {
        &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;query = &lt;SPAN style="COLOR: #2b91af"&gt;Enumerable&lt;/SPAN&gt;.Range(&lt;SPAN style="COLOR: brown"&gt;0&lt;/SPAN&gt;, &lt;SPAN style="COLOR: brown"&gt;100&lt;/SPAN&gt;);
        &lt;SPAN style="COLOR: #2b91af"&gt;Parallel&lt;/SPAN&gt;.ForEach(query, (i, p) =&amp;gt;
        {
            &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(i);
            p.
        });
    }
}&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this code, IntelliSense doesn't show after p. Another great bug from &lt;A href="http://twitter.com/controlflow" mce_href="http://twitter.com/controlflow"&gt;controlflow&lt;/A&gt;. We've fixed this one (it had to deal with picking the right overload of ForEach given an incomplete lambda statement).&lt;/P&gt;
&lt;H3&gt;Debugger data tips are leaking GDI handles&lt;/H3&gt;
&lt;P&gt;Hovering the mouse cursor over variables during debugging and expanding the nodes in the tips will leak GDI handles. After the Visual Studio process will run out of GDI handles (and each process can only allocate 10,000 handles), it will crash. Usually this happens after 10-15 minutes of intensive debugging with datatips, depending on circumstances. You can watch the GDI handles of the devenv.exe process in the Task Manager (if you select GDI in View –&amp;gt; Select Columns).&lt;/P&gt;
&lt;P&gt;This is a stress bug that has been fixed by the debugger team recently.&lt;/P&gt;
&lt;H3&gt;Tooltips on toolbar buttons are not displaying keyboard shortcuts&lt;/H3&gt;
&lt;P&gt;As part of the WPF rewrite, we had postponed this work until very late, and only recently have fixed it (post Beta 2). Now all the keyboard shortcuts show up when you hover your mouse over a toolbar button. You will not be able to turn them off though :)&lt;/P&gt;
&lt;H3&gt;Printing formatted source code with color is not supported&lt;/H3&gt;
&lt;P&gt;This is actually not a bug, it's by design. We had to cut this low-impact feature from 2010 because of tight resources constraints as we've reimplemented the editor from scratch. This feature will hopefully come back in a later release of Visual Studio, maybe as an add-in.&lt;/P&gt;
&lt;H2&gt;More High DPI and other accessibility issues&lt;/H2&gt;
&lt;P&gt;I just keep finding more and more High DPI issues, hoping that if I find and report them now, you guys won't have to.&lt;/P&gt;
&lt;H3&gt;Combobox missing right edge:&lt;/H3&gt;
&lt;P&gt;&lt;A href="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_3.png" mce_href="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_3.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_thumb_3.png" width=267 height=44 mce_src="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_thumb_3.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;shell team decided not to fix this because of tight schedule and resources. &lt;/P&gt;
&lt;H3&gt;Snippets background poorly visible on High Contrast Black&lt;/H3&gt;
&lt;P&gt;&lt;A href="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_4.png" mce_href="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_4.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_thumb_4.png" width=302 height=94 mce_src="http://guilabs.de/images/LiveWriter/VisualStudio2010Beta2KnownIssuesPART2_1453B/image_thumb_4.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The editor team has decided not to fix this because the colors are configurable.&lt;/P&gt;
&lt;H3&gt;Silverlight Out-of-Browser settings dialog clips some controls under 120 DPI&lt;/H3&gt;
&lt;P&gt;We're looking into fixing this right now.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9921253" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/VS+2010/default.aspx">VS 2010</category></item><item><title>A million-dollar pen vs. a pencil</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/11/04/a-million-dollar-pen-vs-a-pencil.aspx</link><pubDate>Thu, 05 Nov 2009 03:30:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9917720</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9917720.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9917720</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9917720</wfw:comment><description>&lt;p&gt;You know this legend about how NASA spent millions &lt;a href="http://en.wikipedia.org/wiki/Space_Pen#Uses_in_the_U.S._and_Russian_space_programs"&gt;to develop a pen that can write in zero gravity&lt;/a&gt;, and the russians have just used a pencil? Well, I was reminded about this by &lt;a href="http://www.ddejan.com/"&gt;Dejan&lt;/a&gt;’s &lt;a href="http://www.ddejan.com/post/2009/10/29/Random-Gradient-Wallpaper-Generator.aspx"&gt;post&lt;/a&gt; in response to my post about the &lt;a href="http://blogs.msdn.com/kirillosenkov/archive/2009/09/28/random-gradient-wallpaper-generator.aspx"&gt;Random Gradient Wallpaper Generator&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I used an O(NxN) algorithm to generate a megapixel image that takes up about 5 MB on my desktop.&lt;/p&gt;  &lt;p&gt;Dejan generated a 2x2 bitmap that takes up 70 bytes and &lt;a href="http://www.ddejan.com/post/2009/10/29/Random-Gradient-Wallpaper-Generator.aspx"&gt;let Windows stretch it&lt;/a&gt; with the exactly same effect. If you read my original post, go read this one, you’ll like it :)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9917720" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Algorithm/default.aspx">Algorithm</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Coding/default.aspx">Coding</category></item><item><title>Bezier Curves and Car Manufacturers</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/11/01/bezier-curves-and-car-manufacturers.aspx</link><pubDate>Mon, 02 Nov 2009 00:52:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9915986</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9915986.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9915986</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9915986</wfw:comment><description>&lt;p&gt;Michael &lt;a href="http://livegeometry.codeplex.com/Thread/View.aspx?ThreadId=72688"&gt;has asked me&lt;/a&gt; if it was possible to add Bezier curves to Live Geometry. So I went ahead and added a Bezier tool (and it took me about 30 minutes to do so!):&lt;/p&gt;  &lt;p&gt;&lt;a title="Go to Live Geometry and try it out!" href="http://livegeometry.com"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/BezierCurvesandCarManufacturers_DF54/image_3.png" width="50" height="59" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This draws a &lt;a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve"&gt;cubic Bezier curve&lt;/a&gt; using four points:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/BezierCurvesandCarManufacturers_DF54/image_5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/BezierCurvesandCarManufacturers_DF54/image_thumb_1.png" width="350" height="261" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;There is something beautiful and elegant about these curves. No wonder industrial designers use it a lot. I actually felt so inspired that I went ahead and used the tool to design a car :) Here's the live view (you need Silverlight 3 to see this), and you can drag the points around:&lt;/p&gt;  &lt;div&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="600" height="300"&gt; &lt;param name="source" value="http://guilabs.de/geometry/LiveGeometry.xap" /&gt; &lt;param name="background" value="white" /&gt; &lt;param name="initParams" value="LoadFile=http://guilabs.de/geometry/drawings/fun/car.lgf,ShowToolbar=false" /&gt; 		  &lt;param name="minRuntimeVersion" value="3.0.40624.0" /&gt; 		   &lt;param name="autoUpgrade" value="true" /&gt; &lt;a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;amp;v=3.0.40624.0" style="text-decoration:none"&gt; &lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none" /&gt;&lt;/a&gt;&lt;/object&gt;&lt;/div&gt;  &lt;div&gt;This is so fascinating. Maybe if I'm tired of programming I should just design cars? ;) Any recruiters from Subaru reading this?&lt;/div&gt;  &lt;div&gt;&amp;#160;&lt;/div&gt;  &lt;div&gt;I also built in a possibility to pass arguments to Live Geometry using &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.startupeventargs.initparams(VS.95).aspx"&gt;initParams&lt;/a&gt;:&lt;/div&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;object &lt;/span&gt;&lt;span style="color: red"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;data:application/x-silverlight-2,&lt;/span&gt;&amp;quot; 
&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;application/x-silverlight-2&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;width&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;100%&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;height&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;100%&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;param &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;source&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;LiveGeometry.xap&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;param &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;initParams&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="background-color: #ffff88; color: blue"&gt;&lt;strong&gt;LoadFile&lt;/strong&gt;=http://guilabs.de/geometry/drawings/fun/car.lgf,&lt;strong&gt;ShowToolbar&lt;/strong&gt;=false&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
&lt;/span&gt;...&lt;/pre&gt;

&lt;div&gt;&lt;/div&gt;

&lt;p&gt;That's how I was able to embed Live Geometry into this page so that it doesn't show the toolbar and it automatically loads the car.lgf drawing.&lt;/p&gt;

&lt;p&gt;Finally, here are some important things to know if you want to host a .xap file from another domain:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;That domain must have crossdomain.xml at its root (so &lt;a href="http://livegeometry.com/crossdomain.xml"&gt;http://livegeometry.com/crossdomain.xml&lt;/a&gt; should be accessible) &lt;/li&gt;

  &lt;li&gt;If you're testing this by loading an .html file from a local filesystem, it will just display a white background and won't load the app. Put the .html on a webserver, then it will work &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9915986" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Coding/default.aspx">Coding</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/LiveGeometry/default.aspx">LiveGeometry</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Irony</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/10/31/irony.aspx</link><pubDate>Sun, 01 Nov 2009 05:50:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9915791</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9915791.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9915791</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9915791</wfw:comment><description>&lt;p&gt;&lt;em&gt;(Ironically, this post is not about irony in it's &lt;/em&gt;&lt;a href="http://en.wikipedia.org/wiki/Irony"&gt;&lt;em&gt;traditional sense&lt;/em&gt;&lt;/a&gt;&lt;em&gt;)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Irony (&lt;a title="http://irony.codeplex.com/" href="http://irony.codeplex.com"&gt;http://irony.codeplex.com&lt;/a&gt;) is an open-source .NET compiler construction framework written by &lt;a href="http://irony-roman.blogspot.com/"&gt;Roman Ivantsov&lt;/a&gt;. It is a &amp;quot;.NET Language Implementation Toolkit&amp;quot;. The language grammar is described in C# (or any other .NET language).&lt;/p&gt;  &lt;p&gt;So instead of generating the scanner and the parser from a grammar description written in an external DSL, Irony uses a .NET object graph to host the grammar description (internal DSL), and it uses this in-memory grammar description to drive the scanner and the parser at runtime.&lt;/p&gt;  &lt;p&gt;One huge advantage of this approach is that the language description becomes orthogonal to the scanner and parser implementation. Writing and maintaining a language becomes easier. See an example of grammar definition further down in this post.&lt;/p&gt;  &lt;h3&gt;Arithmetic expression evaluation&lt;/h3&gt;  &lt;p&gt;The reason I'm talking about all this is that I was looking around for an expression parser for &lt;a href="http://livegeometry.codeplex.com/"&gt;Live Geometry&lt;/a&gt;. I was able to compile expressions earlier &lt;a href="http://blogs.msdn.com/kirillosenkov/archive/2009/03/26/dlr-hosting-in-silverlight.aspx"&gt;using DLR&lt;/a&gt;, but there were two issues with that.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;First, DLR has quite a footprint – adding a dependency on DLR to a Silverlight binary can grow the size of the .xap file from 400 KB to 1400 KB – and that's not good. &lt;/li&gt;    &lt;li&gt;Second, DLR didn't seem to expose the parse trees easily – and I do need the access to the parse trees for inspection and manipulation, such as calculating dependencies between formulas. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;So I started looking around. There are really a lot of related projects out there, I'll just mention the ones on CodePlex:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://antlrcsharp.codeplex.com"&gt;http://&lt;strong&gt;antlrcsharp&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://csparser.codeplex.com/" href="http://csparser.codeplex.com"&gt;http://&lt;strong&gt;csparser&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://expressioneval.codeplex.com/" href="http://expressioneval.codeplex.com"&gt;http://&lt;strong&gt;expressioneval&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://flee.codeplex.com/" href="http://flee.codeplex.com"&gt;http://&lt;strong&gt;flee&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://ilcalc.codeplex.com/" href="http://ilcalc.codeplex.com"&gt;http://&lt;strong&gt;ilcalc&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://lazyparser.codeplex.com/" href="http://lazyparser.codeplex.com"&gt;http://&lt;strong&gt;lazyparser&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://linqovercsharp.codeplex.com/" href="http://linqovercsharp.codeplex.com"&gt;http://&lt;strong&gt;linqovercsharp&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://ncalc.codeplex.com/" href="http://ncalc.codeplex.com"&gt;http://&lt;strong&gt;ncalc&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://simpleexpressioneval.codeplex.com/" href="http://simpleexpressioneval.codeplex.com"&gt;http://&lt;strong&gt;simpleexpressioneval&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://simplemathparser.codeplex.com/" href="http://simplemathparser.codeplex.com"&gt;http://&lt;strong&gt;simplemathparser&lt;/strong&gt;.codeplex.com&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;There might be more. My requirements were for the tool to output a parse tree and give me full access to it. Another requirement is that the grammar description has to be as simple as possible and as flexible and extensible as possible (because I planned to extend the language with custom elements such as method calls and property access). However full blown C# and LINQ parsers were an overkill. Other good projects were really fast, but didn't give me the parse tree.&lt;/p&gt;  &lt;p&gt;So I settled on Irony, and so far I'm pretty happy that I did. It didn't provide the Silverlight version out of the box, but I'm talking with Roman about Silverlight support. For now, it took me an hour to make the Irony sources build for Silverlight and I built a nice little Irony.Silverlight.dll for my own project.&lt;/p&gt;  &lt;h3&gt;Expression parser in Irony&lt;/h3&gt;  &lt;p&gt;Here's how I declared the grammar for the language that I need:&lt;/p&gt;  &lt;pre style="font-family: consolas, font-size: 2" class="code"&gt;&lt;span style="color: green"&gt;// This grammar is based on the ExpressionEvaluatorGrammar from Irony.Samples
// Copyright (c) Roman Ivantsov
// Details at &lt;a href="http://irony.codeplex.com"&gt;http://irony.codeplex.com&lt;/a&gt;&lt;/span&gt;
[&lt;span style="color: #2b91af"&gt;Language&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Expression&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;Dynamic geometry expression evaluator&amp;quot;&lt;/span&gt;)]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ExpressionGrammar &lt;/span&gt;: Irony.Parsing.&lt;span style="color: #2b91af"&gt;Grammar
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;public &lt;/span&gt;ExpressionGrammar()
    {
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.GrammarComments = &lt;span style="color: #a31515"&gt;@&amp;quot;Arithmetical expressions for dynamic geometry.&amp;quot;&lt;/span&gt;;

        &lt;span style="color: green"&gt;// 1. Terminals
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;number = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NumberLiteral&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;number&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;identifier = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IdentifierTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;identifier&amp;quot;&lt;/span&gt;);

        &lt;span style="color: green"&gt;// 2. Non-terminals
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;Expr = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Expr&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;Term = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Term&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;BinExpr = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;BinExpr&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;ParExpr = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;ParExpr&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;UnExpr = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;UnExpr&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;UnOp = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;UnOp&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;BinOp = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;BinOp&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;operator&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;PostFixExpr = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;PostFixExpr&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;PostFixOp = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;PostFixOp&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;AssignmentStmt = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;AssignmentStmt&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;AssignmentOp = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;AssignmentOp&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;PropertyAccess = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;PropertyAccess&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;FunctionCall = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NonTerminal&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;FunctionCall&amp;quot;&lt;/span&gt;);

        &lt;span style="color: green"&gt;// 3. BNF rules
        &lt;/span&gt;Expr.Rule = Term | UnExpr | FunctionCall | PropertyAccess | BinExpr;
        Term.Rule = number | ParExpr | identifier;
        ParExpr.Rule = &lt;span style="color: #a31515"&gt;&amp;quot;(&amp;quot; &lt;/span&gt;+ Expr + &lt;span style="color: #a31515"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;;
        UnExpr.Rule = UnOp + Term;
        UnOp.Rule = ToTerm(&lt;span style="color: #a31515"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;) | &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot; &lt;/span&gt;| &lt;span style="color: #a31515"&gt;&amp;quot;++&amp;quot; &lt;/span&gt;| &lt;span style="color: #a31515"&gt;&amp;quot;--&amp;quot;&lt;/span&gt;;
        BinExpr.Rule = Expr + BinOp + Expr;
        BinOp.Rule = ToTerm(&lt;span style="color: #a31515"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;) | &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot; &lt;/span&gt;| &lt;span style="color: #a31515"&gt;&amp;quot;*&amp;quot; &lt;/span&gt;| &lt;span style="color: #a31515"&gt;&amp;quot;/&amp;quot; &lt;/span&gt;| &lt;span style="color: #a31515"&gt;&amp;quot;^&amp;quot;&lt;/span&gt;;
        PropertyAccess.Rule = identifier + &lt;span style="color: #a31515"&gt;&amp;quot;.&amp;quot; &lt;/span&gt;+ identifier;
        FunctionCall.Rule = identifier + ParExpr;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.Root = Expr;

        &lt;span style="color: green"&gt;// 4. Operators precedence
        &lt;/span&gt;RegisterOperators(1, &lt;span style="color: #a31515"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;);
        RegisterOperators(2, &lt;span style="color: #a31515"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;);
        RegisterOperators(3, &lt;span style="color: #2b91af"&gt;Associativity&lt;/span&gt;.Right, &lt;span style="color: #a31515"&gt;&amp;quot;^&amp;quot;&lt;/span&gt;);

        RegisterPunctuation(&lt;span style="color: #a31515"&gt;&amp;quot;(&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;.&amp;quot;&lt;/span&gt;);
        MarkTransient(Term, Expr, BinOp, UnOp, AssignmentOp, ParExpr);
    }
}&lt;/pre&gt;

&lt;h1&gt;&lt;/h1&gt;

&lt;p&gt;That's it! Note how Irony uses operator overloading for | and + to build rules. We need ToTerm(&amp;quot;+&amp;quot;) call on any of the operands to give the C# compiler a hint about the types so the operator overloading can succeed. This is a good example of an internal DSL hosted in C#.&lt;/p&gt;

&lt;h3&gt;Consuming the parse tree&lt;/h3&gt;

&lt;p&gt;Now, here's how to use the ExpressionGrammar class to create and use a parser:&lt;/p&gt;

&lt;pre style="font-family: consolas, font-size: 2" class="code"&gt;&lt;span style="color: #2b91af"&gt;Grammar &lt;/span&gt;grammar = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ExpressionGrammar&lt;/span&gt;();
&lt;span style="color: #2b91af"&gt;Parser &lt;/span&gt;parser = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Parser&lt;/span&gt;(grammar);
&lt;span style="color: #2b91af"&gt;ParseTree &lt;/span&gt;parseTree = parser.Parse(&lt;span style="color: #a31515"&gt;&amp;quot;sin(2 * x) + 1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;h3&gt;Producing a LINQ Expression Tree from a parse tree&lt;/h3&gt;

&lt;p&gt;Now, given the parse tree from the previous step, I just quickly wrote an ExpressionTreeBuilder that produces a bound expression tree out of it, and a Binder that helps resolve names. The Compiler class is a façade for the whole thing:&lt;/p&gt;

&lt;hr /&gt;

&lt;pre style="font-family: consolas, font-size: 2" class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Compiler
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;double&lt;/span&gt;, &lt;span style="color: blue"&gt;double&lt;/span&gt;&amp;gt; CompileFunction(&lt;span style="color: blue"&gt;string &lt;/span&gt;functionText)
    {
        &lt;span style="color: #2b91af"&gt;ParseTree &lt;/span&gt;ast = ParserInstance.Parse(functionText);
        &lt;span style="color: #2b91af"&gt;ExpressionTreeBuilder &lt;/span&gt;builder = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ExpressionTreeBuilder&lt;/span&gt;();
        &lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;double&lt;/span&gt;, &lt;span style="color: blue"&gt;double&lt;/span&gt;&amp;gt;&amp;gt; expression = builder.CreateFunction(ast.Root);
        &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;double&lt;/span&gt;, &lt;span style="color: blue"&gt;double&lt;/span&gt;&amp;gt; function = expression.Compile();
        &lt;span style="color: blue"&gt;return &lt;/span&gt;function;
    }

    &lt;span style="color: blue"&gt;static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Parser &lt;/span&gt;ParserInstance = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Parser&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ExpressionGrammar&lt;/span&gt;.Instance);
}

&lt;hr /&gt;

&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binder
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;public void &lt;/span&gt;RegisterParameter(&lt;span style="color: #2b91af"&gt;ParameterExpression &lt;/span&gt;parameter)
    {
        parameters.Add(parameter.Name, parameter);
    }

    &lt;span style="color: #2b91af"&gt;ParameterExpression &lt;/span&gt;ResolveParameter(&lt;span style="color: blue"&gt;string &lt;/span&gt;parameterName)
    {
        &lt;span style="color: #2b91af"&gt;ParameterExpression &lt;/span&gt;parameter;
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(parameters.TryGetValue(parameterName, &lt;span style="color: blue"&gt;out &lt;/span&gt;parameter))
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;parameter;
        }
        &lt;span style="color: blue"&gt;return null&lt;/span&gt;;
    }

    &lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;ParameterExpression&lt;/span&gt;&amp;gt; parameters = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;ParameterExpression&lt;/span&gt;&amp;gt;();

    &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;Resolve(&lt;span style="color: blue"&gt;string &lt;/span&gt;identifier)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;ResolveParameter(identifier);
    }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MethodInfo &lt;/span&gt;ResolveMethod(&lt;span style="color: blue"&gt;string &lt;/span&gt;functionName)
    {
        &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;methodInfo &lt;span style="color: blue"&gt;in typeof&lt;/span&gt;(System.&lt;span style="color: #2b91af"&gt;Math&lt;/span&gt;).GetMethods())
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(methodInfo.Name.Equals(functionName, &lt;span style="color: #2b91af"&gt;StringComparison&lt;/span&gt;.InvariantCultureIgnoreCase))
            {
                &lt;span style="color: blue"&gt;return &lt;/span&gt;methodInfo;
            }
        }
        &lt;span style="color: blue"&gt;return null&lt;/span&gt;;
    }
}&lt;/pre&gt;

&lt;hr /&gt;

&lt;pre style="font-family: consolas, font-size: 2" class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ExpressionTreeBuilder
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;public &lt;/span&gt;ExpressionTreeBuilder()
    {
        Binder = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binder&lt;/span&gt;();
    }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binder &lt;/span&gt;Binder { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;double&lt;/span&gt;, &lt;span style="color: blue"&gt;double&lt;/span&gt;&amp;gt;&amp;gt; CreateFunction(&lt;span style="color: #2b91af"&gt;ParseTreeNode &lt;/span&gt;root)
    {
        &lt;span style="color: #2b91af"&gt;ParameterExpression &lt;/span&gt;parameter = &lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Parameter(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: blue"&gt;double&lt;/span&gt;), &lt;span style="color: #a31515"&gt;&amp;quot;x&amp;quot;&lt;/span&gt;);
        Binder.RegisterParameter(parameter);
        &lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;body = CreateExpression(root);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;result = &lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Lambda&amp;lt;&lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;double&lt;/span&gt;, &lt;span style="color: blue"&gt;double&lt;/span&gt;&amp;gt;&amp;gt;(body, parameter);
        &lt;span style="color: blue"&gt;return &lt;/span&gt;result;
    }

    &lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;CreateExpression(&lt;span style="color: #2b91af"&gt;ParseTreeNode &lt;/span&gt;root)
    {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(root.Term.Name == &lt;span style="color: #a31515"&gt;&amp;quot;BinExpr&amp;quot;&lt;/span&gt;)
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;CreateBinaryExpression(root);
        }

        &lt;span style="color: blue"&gt;if &lt;/span&gt;(root.Term.Name == &lt;span style="color: #a31515"&gt;&amp;quot;identifier&amp;quot;&lt;/span&gt;)
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;Binder.Resolve(root.Token.Text);
        }

        &lt;span style="color: blue"&gt;if &lt;/span&gt;(root.Term.Name == &lt;span style="color: #a31515"&gt;&amp;quot;number&amp;quot;&lt;/span&gt;)
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;CreateLiteralExpression(&lt;span style="color: #2b91af"&gt;Convert&lt;/span&gt;.ToDouble(root.Token.Value));
        }

        &lt;span style="color: blue"&gt;if &lt;/span&gt;(root.Term.Name == &lt;span style="color: #a31515"&gt;&amp;quot;FunctionCall&amp;quot;&lt;/span&gt;)
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;CreateCallExpression(root);
        }

        &lt;span style="color: blue"&gt;return null&lt;/span&gt;;
    }

    &lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;CreateCallExpression(&lt;span style="color: #2b91af"&gt;ParseTreeNode &lt;/span&gt;root)
    {
        &lt;span style="color: blue"&gt;string &lt;/span&gt;functionName = root.ChildNodes[0].Token.Text;
        &lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;argument = CreateExpression(root.ChildNodes[1]);
        &lt;span style="color: #2b91af"&gt;MethodInfo &lt;/span&gt;method = Binder.ResolveMethod(functionName);
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Call(method, argument);
    }

    &lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;CreateLiteralExpression(&lt;span style="color: blue"&gt;double &lt;/span&gt;arg)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Constant(arg);
    }

    &lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;CreateBinaryExpression(&lt;span style="color: #2b91af"&gt;ParseTreeNode &lt;/span&gt;node)
    {
        &lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;left = CreateExpression(node.ChildNodes[0]);
        &lt;span style="color: #2b91af"&gt;Expression &lt;/span&gt;right = CreateExpression(node.ChildNodes[2]);

        &lt;span style="color: blue"&gt;switch &lt;/span&gt;(node.ChildNodes[1].Term.Name)
        {
            &lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;:
                &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Add(left, right);
            &lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;:
                &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Subtract(left, right);
            &lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;:
                &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Multiply(left, right);
            &lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;:
                &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Divide(left, right);
            &lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;^&amp;quot;&lt;/span&gt;:
                &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Expression&lt;/span&gt;.Power(left, right);
        }
        &lt;span style="color: blue"&gt;return null&lt;/span&gt;;
    }
}&lt;/pre&gt;

&lt;p&gt;This just demonstrates the principle. One could easily extend this to write a full blown expression compiler, but this is good enough for my purposes for now. Live Geometry now uses this to evaluate math expressions and plot function graphs. As always, you can get the source from &lt;a href="http://livegeometry.codeplex.com/SourceControl/ListDownloadableCommits.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9915791" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Coding/default.aspx">Coding</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/LiveGeometry/default.aspx">LiveGeometry</category></item><item><title>Indexed Properties in C# 4.0</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/10/20/indexed-properties-in-c-4-0.aspx</link><pubDate>Wed, 21 Oct 2009 06:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9910397</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9910397.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9910397</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9910397</wfw:comment><description>&lt;p&gt;Executive summary:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In C# 4.0 you can call parameterized properties declared in COM using the indexer syntax, for instance instead of excel.get_Range(&amp;quot;a&amp;quot;) you can now write excel.Range[&amp;quot;a&amp;quot;]. &lt;/li&gt;    &lt;li&gt;You can’t declare your own indexed properties from C#. We have no plans of adding the ability to declare your own properties with parameters. Instead, the recommended way is to use a type with an indexer. &lt;/li&gt;    &lt;li&gt;The feature is immediately available in Visual Studio 2010 Beta 2 for your indexing pleasure. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;So I guess this hasn’t had a lot of press coverage so far (although Sam &lt;a href="http://blogs.msdn.com/samng/archive/2009/06/16/com-interop-in-c-4-0.aspx" mce_href="http://blogs.msdn.com/samng/archive/2009/06/16/com-interop-in-c-4-0.aspx"&gt;hinted about it&lt;/a&gt;). Even the published &lt;a href="http://download.microsoft.com/download/7/E/6/7E6A548C-9C20-4C80-B3B8-860FAF20887A/CSharp%204.0%20Specification.doc" mce_href="http://download.microsoft.com/download/7/E/6/7E6A548C-9C20-4C80-B3B8-860FAF20887A/CSharp%204.0%20Specification.doc"&gt;C# 4.0 language specification&lt;/a&gt; and the &lt;a href="http://code.msdn.microsoft.com/csharpfuture/" mce_href="http://code.msdn.microsoft.com/csharpfuture/"&gt;C# Future page&lt;/a&gt; still don’t mention it as of now. This is because we’ve implemented this feature very late in the cycle, as a DCR (Design Change Request). The language design team felt that we should complete the COM interop story in 4.0 and this one was the last missing piece of the puzzle. When &lt;a href="http://paulvanbrenk.com/" mce_href="http://paulvanbrenk.com/"&gt;Paul&lt;/a&gt; was in Redmond this summer, he was tasked with testing the IDE support for this feature, and I was helping out with the test infrastructure.&lt;/p&gt;  &lt;h3&gt;The new syntax&lt;/h3&gt;  &lt;p&gt;The pattern is very simple. Wherever you use COM interop and have to call get_X() and set_X(), now you can just call X[], which we feel is a more natural syntax:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;font size="2" face="Consolas"&gt;&lt;span style="color: green"&gt;// before
&lt;/span&gt;excel.get_Range(&lt;span style="color: #a31515"&gt;&amp;quot;A1&amp;quot;&lt;/span&gt;).set_Value(&lt;span style="color: #2b91af"&gt;Type&lt;/span&gt;.Missing, &lt;span style="color: #a31515"&gt;&amp;quot;ID&amp;quot;&lt;/span&gt;);

&lt;span style="color: green"&gt;// after
&lt;/span&gt;excel.Range[&lt;span style="color: #a31515"&gt;&amp;quot;A1&amp;quot;&lt;/span&gt;].Value = &lt;span style="color: #a31515"&gt;&amp;quot;ID&amp;quot;&lt;/span&gt;;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;Let’s also take &lt;a href="http://www.hanselman.com/blog/CLRAndDLRAndBCLOhMyWhirlwindTourAroundNET4AndVisualStudio2010Beta1.aspx" mce_href="http://www.hanselman.com/blog/CLRAndDLRAndBCLOhMyWhirlwindTourAroundNET4AndVisualStudio2010Beta1.aspx"&gt;Scott Hanselman’s example&lt;/a&gt; from Beta 1:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;font size="2" face="Consolas"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;excel = &lt;span style="color: blue"&gt;new &lt;/span&gt;Excel.&lt;span style="color: #2b91af"&gt;Application&lt;/span&gt;();
excel.Visible = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
excel.Workbooks.Add();
excel.&lt;strong&gt;&lt;font color="#ff0000"&gt;get_&lt;/font&gt;&lt;/strong&gt;Range&lt;strong&gt;&lt;font color="#ff0000"&gt;(&lt;/font&gt;&lt;/strong&gt;&lt;span style="color: #a31515"&gt;&amp;quot;A1&amp;quot;&lt;/span&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;)&lt;/font&gt;&lt;/strong&gt;.Value&lt;font color="#ff0000"&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/font&gt; = &lt;span style="color: #a31515"&gt;&amp;quot;Process Name&amp;quot;&lt;/span&gt;;
excel.&lt;strong&gt;&lt;font color="#ff0000"&gt;get_&lt;/font&gt;&lt;/strong&gt;Range&lt;strong&gt;&lt;font color="#ff0000"&gt;(&lt;/font&gt;&lt;/strong&gt;&lt;span style="color: #a31515"&gt;&amp;quot;B1&amp;quot;&lt;/span&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;)&lt;/font&gt;&lt;/strong&gt;.Value&lt;font color="#ff0000"&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/font&gt; = &lt;span style="color: #a31515"&gt;&amp;quot;Memory Usage&amp;quot;&lt;/span&gt;;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;Now you can simplify this even further:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;font size="2" face="Consolas"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;excel = &lt;span style="color: blue"&gt;new &lt;/span&gt;Excel.&lt;span style="color: #2b91af"&gt;Application&lt;/span&gt;();
excel.Visible = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
excel.Workbooks.Add();
excel.Range[&lt;span style="color: #a31515"&gt;&amp;quot;A1&amp;quot;&lt;/span&gt;].Value = &lt;span style="color: #a31515"&gt;&amp;quot;Process Name&amp;quot;&lt;/span&gt;;
excel.Range[&lt;span style="color: #a31515"&gt;&amp;quot;B1&amp;quot;&lt;/span&gt;].Value = &lt;span style="color: #a31515"&gt;&amp;quot;Memory Usage&amp;quot;&lt;/span&gt;;&lt;/font&gt;&lt;/pre&gt;

&lt;p mce_keep="true"&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This is just syntactic sugar – the compiler emits calls to the get_ and set_ accessors behind the stage.&lt;/p&gt;

&lt;h3&gt;Omitting []&lt;/h3&gt;

&lt;p&gt;In case that all the parameters are optional and none of the arguments are specified, you should omit the empty []. Having Value[] is illegal.&lt;/p&gt;

&lt;p&gt;This is the reason you can replace Value2 with Value in the example above: Value is an indexed property and you’re calling it without specifying any arguments – in this case we omit the brackets [] altogether. Earlier, without indexed properties support, we had to introduce the ugly Value2, because you otherwise had to call get_Value().&lt;/p&gt;

&lt;h3&gt;IDE support&lt;/h3&gt;

&lt;p&gt;My team, on the IDE side, provided IntelliSense support for this new language feature:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;completion list:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_thumb_1.png" width="381" height="94" mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_thumb_1.png" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;parameter help:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_thumb.png" width="502" height="62" mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_thumb.png" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;however Quick Info still shows you that in reality the call simply binds to the get_Range method:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_thumb_2.png" width="587" height="83" mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/IndexedPropertiesinC4.0_14F1B/image_thumb_2.png" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we were designing the feature, it turned out that adding compiler support for it is not the only tricky part. There were a couple of interesting problems in the IDE space as well. For example, what do you show in Quick Info for the following intexed property call?&lt;/p&gt;

&lt;p&gt;A.B[C]++;&lt;/p&gt;

&lt;p&gt;Do we now show get_B or set_B?&lt;/p&gt;

&lt;p&gt;When the IDE can’t guess which accessor we’re talking about (for example, in incomplete code), we by default bind to the get_accessor.&lt;/p&gt;

&lt;h3&gt;Backwards compatibility&lt;/h3&gt;

&lt;p&gt;For backwards compatibility reasons, using the accessors get_ and set_ directly is still valid and available in IntelliSense, because we didn’t want to break all existing COM interop code out there.&lt;/p&gt;

&lt;h3&gt;Why not allow declaring indexed properties in C#?&lt;/h3&gt;

&lt;p&gt;A common question that we expect we’ll be getting is “why just consume? why not allow to declare such properties in C#?”. Well, the answer is not even that &lt;font color="#800080" face="Lucida Sans Unicode"&gt;we first have to cost, design, spec, prototype, implement and test this feature&lt;/font&gt;, but rather that we think that declaring a type with an indexer is a preferred approach. It’s useful to separate the responsibilities:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The property is there to get an object. The property belongs to the parent object. &lt;/li&gt;

  &lt;li&gt;The indexer is there on the returned object to enumerate it. The indexer belongs to the returned object. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We shouldn’t be mixing these together.&lt;/p&gt;

&lt;h3&gt;Static or dynamic?&lt;/h3&gt;

&lt;p&gt;Accessing indexed properties is supported from both static and dynamic code.&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.msdn.com%2fkirillosenkov%2farchive%2f2009%2f10%2f20%2findexed-properties-in-c-4-0.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.msdn.com%2fkirillosenkov%2farchive%2f2009%2f10%2f20%2findexed-properties-in-c-4-0.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.msdn.com%2fkirillosenkov%2farchive%2f2009%2f10%2f20%2findexed-properties-in-c-4-0.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.msdn.com%2fkirillosenkov%2farchive%2f2009%2f10%2f20%2findexed-properties-in-c-4-0.aspx" /&gt;&lt;/a&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9910397" width="1" height="1"&gt;</description></item><item><title>Visual Studio 2010 Beta 2 Known Issues</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/10/19/visual-studio-2010-beta-2-known-issues.aspx</link><pubDate>Mon, 19 Oct 2009 23:04:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9909514</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>14</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9909514.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9909514</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9909514</wfw:comment><description>&lt;p&gt;&lt;em&gt;[This is Part 1. Read Part 2 &lt;/em&gt;&lt;a href="http://blogs.msdn.com/kirillosenkov/archive/2009/11/12/visual-studio-2010-beta-2-known-issues-part-2.aspx"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;em&gt;]&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Now that we’ve shipped Beta2 and the world is busy downloading the fresh new bits, I’m very excited to know what do you guys think? Will you like it? Will there be major issues that we missed? Time will show :)&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a title="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx&lt;/a&gt; – the Beta 2 start page &lt;/li&gt;    &lt;li&gt;&lt;a href="http://connect.microsoft.com/visualstudio/feedback"&gt;http://connect.microsoft.com/visualstudio/feedback&lt;/a&gt; – official feedback channel &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;By definition, this Beta 2 release is not final, and there are still bugs lurking around out there. We are very busy fixing those bugs for RTM, but for now, there are some that we haven’t had time to fix before Beta2. &lt;/p&gt;  &lt;p&gt;This post lists some of the known issues that are in VS 2010 Beta 2. It’s not in my powers to maintain a comprehensive list here, I’ll just mention the ones which I was personally involved with in my day-to-day work. Apologies that I have found them too late, but I guess better late then never...&lt;/p&gt;  &lt;h2&gt;Updates&lt;font color="#ff0000"&gt; – new!&lt;/font&gt;&lt;/h2&gt;  &lt;h3&gt;Posted the Part 2 of the issues &lt;font color="#0080ff"&gt;(updated 11/12/2009)&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a title="http://blogs.msdn.com/kirillosenkov/archive/2009/11/12/visual-studio-2010-beta-2-known-issues-part-2.aspx" href="http://blogs.msdn.com/kirillosenkov/archive/2009/11/12/visual-studio-2010-beta-2-known-issues-part-2.aspx"&gt;&lt;strong&gt;http://blogs.msdn.com/kirillosenkov/archive/2009/11/12/visual-studio-2010-beta-2-known-issues-part-2.aspx&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;All further updates will happen there or will wait until Part 3.&lt;/p&gt;  &lt;h3&gt;The official Beta2 known issues list &lt;font color="#0080ff"&gt;(updated 10/26/2009)&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a title="http://go.microsoft.com/fwlink/?LinkID=166199" href="http://go.microsoft.com/fwlink/?LinkID=166199"&gt;http://go.microsoft.com/fwlink/?LinkID=166199&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Updating the .sln file from Beta1 to Beta2 &lt;font color="#0080ff"&gt;(updated 10/26/2009)&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;Need to upgrade .sln file from Beta2 in order to be able to double-click it. See Jon’s post here for more details:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://msmvps.com/blogs/jon_skeet/archive/2009/10/26/migrating-from-visual-studio-2010-beta-1-to-beta-2-solution-file-change-required.aspx" href="http://msmvps.com/blogs/jon_skeet/archive/2009/10/26/migrating-from-visual-studio-2010-beta-1-to-beta-2-solution-file-change-required.aspx"&gt;http://msmvps.com/blogs/jon_skeet/archive/2009/10/26/migrating-from-visual-studio-2010-beta-1-to-beta-2-solution-file-change-required.aspx&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Setup dialog UI layout wrong on High DPI&lt;/h3&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010Beta2KnownIssues_C54F/image_5db5462e-9542-466a-9b85-8a8f7fb05859.png" width="640" height="452" /&gt; &lt;/p&gt;  &lt;p&gt;Embarrassing! Unfortunately, not everyone on the Visual Studio team is rigorous about non-default testing, such as High DPI, Accessibility, etc. We will hopefully fix this one before RTM. Also recent data shows that non-96 DPI is a very common setting, a lot of people actually use 120 DPI and others. I personally use 120 DPI, that’s how I find these bugs.&lt;/p&gt;  &lt;h3&gt;SmartTag high DPI issues&lt;/h3&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010Beta2KnownIssues_C54F/image_80bdf462-332e-4211-a3ea-dee3c0222937.png" width="315" height="223" /&gt; &lt;/p&gt;  &lt;p&gt;With high DPI, the SmartTag menu is missing horizontal menu separator bars. Also the right vertical edge of the SmartTag button disappears. These bugs are a recent regression from WPF introducing the &lt;a href="http://blogs.msdn.com/text/archive/2009/08/27/layout-rounding.aspx"&gt;UseLayoutRounding&lt;/a&gt; API. The WPF team is looking into fixing these issues before the release.&lt;/p&gt;  &lt;h3&gt;QuickInfo tooltip trimmed at high DPI&lt;/h3&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010Beta2KnownIssues_C54F/image_61e6d020-aa55-4f1b-b135-18ee12e0bf1d.png" width="373" height="67" /&gt;&lt;/p&gt;  &lt;p&gt;This is another regression from the new DWrite technology. The last word in the tooltip is missing! This one is fixed already.&lt;/p&gt;  &lt;h3&gt;Thin line on top of the active document tab&lt;/h3&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010Beta2KnownIssues_C54F/image_dc57cb09-3a23-4083-a90e-19ef2761f76a.png" width="142" height="51" /&gt;&lt;/p&gt;  &lt;p&gt;Again, another high DPI issue. You can only notice this one if you look closely. We’ve fixed this already as well. &lt;/p&gt;  &lt;h3&gt;Outlining Expand/Collapse glyphs are shifted several pixels up&lt;/h3&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010Beta2KnownIssues_C54F/image_96eca590-702c-4845-bb4a-d368608f5969.png" width="151" height="118" /&gt;&lt;/p&gt;  &lt;p&gt;Fixed already. A lot of people complained about this internally.&lt;/p&gt;  &lt;h3&gt;Zoom combobox in the bottom-left corner of the editor isn’t aligned with the horizontal scrollbar&lt;/h3&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010Beta2KnownIssues_C54F/image_8a6d5bbc-56ef-4c68-96a4-d3602ed1d295.png" width="122" height="93" /&gt;&lt;/p&gt;  &lt;p&gt;This is fixed. &lt;/p&gt;  &lt;h3&gt;Don’t tear off the Call Hierarchy tool window!&lt;/h3&gt;  &lt;p&gt;When you try to undock the C# Call Hierarchy toolwindow and drag it away (for example, to another monitor), VS will crash. This one is too embarrassing, because I was the one who is responsible for testing Call Hierarchy. To my defense, I was on vacation when this regressed and when I came back and found this, it was too late to fix. Shell UI team changed something about the WPF toolwindow implementation and we had some layout logic that didn’t expect double.Infinity as an argument, so we crashed. This one’s already fixed in recent builds.&lt;/p&gt;  &lt;h3&gt;Vertical separator bar in the Call Hierarchy tool window doesn’t resize the details pane&lt;/h3&gt;  &lt;p&gt;This also only reproes under 120 DPI and above. You can’t resize the two panes below by dragging the vertical bar:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010Beta2KnownIssues_C54F/image_fcb1eaa2-a42d-410d-8652-0e500a7cfe73.png" width="660" height="256" /&gt; &lt;/p&gt;  &lt;p&gt;And again, this is one that I should have caught and missed. When I caught this, it was too late to fix for Beta2. The WPF team is looking at this one right now.&lt;/p&gt;  &lt;h3&gt;Error message connecting to a TFS server via HTTPS&lt;/h3&gt;  &lt;p&gt;Well, guess what, the TFS client team has done it again! TFS HTTPS story was broken in Beta1, and it still has a bug in Beta2. However the good news is that there is a really easy workaround this time.&lt;/p&gt;  &lt;p&gt;When adding a new TFS HTTPS webserver (e.g. a Codeplex server at &lt;a href="http://codeplex.com"&gt;http://codeplex.com&lt;/a&gt;), after entering your credentials you will see this:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010Beta2KnownIssues_C54F/image_7060cd8d-7a03-4049-91d5-96ee99571d1f.png" width="558" height="458" /&gt; &lt;/p&gt;  &lt;p&gt;Don’t panic! Just enter your credentials again and things will work just fine. If you used the Tip (&lt;a title="http://blogs.msdn.com/kirillosenkov/archive/2009/09/27/tip-don-t-enter-your-codeplex-credentials-every-time.aspx" href="http://blogs.msdn.com/kirillosenkov/archive/2009/09/27/tip-don-t-enter-your-codeplex-credentials-every-time.aspx"&gt;http://blogs.msdn.com/kirillosenkov/archive/2009/09/27/tip-don-t-enter-your-codeplex-credentials-every-time.aspx&lt;/a&gt;), then you will be unaffected by this and things will hopefully run smoothly.&lt;/p&gt;  &lt;h3&gt;Ctrl+Alt+DOWN ARROW doesn’t bring up the active document list&lt;/h3&gt;  &lt;p&gt;Ctrl+Alt+Down used to bring up the active document list, in Beta2 it doesn’t. This is fixed.&lt;/p&gt;  &lt;h3&gt;Start Page: scroll wheel doesn’t work at the news feed&lt;/h3&gt;  &lt;p&gt;Also the scrollbar thumb only moves in discrete steps. The Shell UI team decided not to fix this, because they don’t have time and resources for this. I actually was surprised to discover that the scrollbar didn’t work in 2008 either. Never noticed this until recently.&lt;/p&gt;  &lt;h3&gt;VS Command prompt shortcut is not getting installed if you don’t install C++&lt;/h3&gt;  &lt;p&gt;This one will be fixed as well.&lt;/p&gt;  &lt;h3&gt;Hovering over ‘var’ during debugging doesn’t show the inferred type&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.wintellect.com/cs/blogs/jeffreyr/"&gt;Jeffrey Richter&lt;/a&gt; told me about this minor annoyance. Although our language service correctly reports the inferred type when you hover the mouse cursor over ‘var’ in design time, it doesn’t work in debug mode. Since Jeff teaches a lot of courses in debugging and threading, this was bugging him ever since we shipped C# 3.0. Well, we finally fixed it for 2010 RTM. Thanks to Jeff for reporting this!&lt;/p&gt;  &lt;h3&gt;Visual Studio doesn’t start maximized when first launched&lt;/h3&gt;  &lt;p&gt;A while back I’ve logged a bug against the Shell team to “just start VS maximized for heaven’s sake”. They did the fix, but somehow it didn’t make it into the Beta2 branch. They’ll hopefully fix this for RTM.&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;Well, these were the ones worth mentioning I guess. Apologies if you run into any of these or any other bugs for that matter. I will keep updating this post with more issues that I find or I think users should be aware of. Please keep in mind that this is an unofficial list.&lt;/p&gt;  &lt;p&gt;Please do let us know about any issues you find by submitting a connect bug. If the bug/suggestion/feedback is related to the C# language or IDE, also feel free to let me know directly or leave a comment on this blog. Since I work closely with the VS editor team, it’s worth watching their blog and giving them feedback: &lt;a title="http://blogs.msdn.com/vseditor" href="http://blogs.msdn.com/vseditor"&gt;http://blogs.msdn.com/vseditor&lt;/a&gt;. Also, if you have any feedback about the new text rendering in WPF 4.0 and Visual Studio, the WPF Text team has a blog here: &lt;a href="http://blogs.msdn.com/text"&gt;http://blogs.msdn.com/text&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9909514" width="1" height="1"&gt;</description></item><item><title>Saving images (.bmp, .png, etc) in WPF/Silverlight</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/10/12/saving-images-bmp-png-etc-in-wpf-silverlight.aspx</link><pubDate>Mon, 12 Oct 2009 22:48:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9906332</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9906332.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9906332</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9906332</wfw:comment><description>&lt;p&gt;I’ve recently added a new feature to &lt;a href="http://livegeometry.com"&gt;Live Geometry&lt;/a&gt; that allows users to save the current drawing as a bitmap or a .png file. Just push the save button and pick the desired image format in the Save dialog:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/Savingimages.bmp.pngetcinWPFSilverlight_C005/image_ed62416e-ff7f-4bb0-88eb-f2d38ec6f61c.png" width="275" height="127" /&gt; &lt;/p&gt;  &lt;p&gt;Fortunately, both WPF and Silverlight support saving full visual contents of any visual into a file on disk. However the approach is somewhat different.&lt;/p&gt;  &lt;h3&gt;Saving images in WPF&lt;/h3&gt;  &lt;p&gt;WPF can save any Visual to an image and it supports several formats out of the box via a concept of Encoders. Here’s a sample for .bmp and .png:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;font size="2" face="Consolas"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;SaveToBmp(&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;visual, &lt;span style="color: blue"&gt;string &lt;/span&gt;fileName)
{
    &lt;span style="color: blue"&gt;var &lt;/span&gt;encoder = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bmpbitmapencoder.aspx"&gt;BmpBitmapEncoder&lt;/a&gt;&lt;/span&gt;();
    SaveUsingEncoder(visual, fileName, encoder);
}

&lt;span style="color: blue"&gt;void &lt;/span&gt;SaveToPng(&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;visual, &lt;span style="color: blue"&gt;string &lt;/span&gt;fileName)
{
    &lt;span style="color: blue"&gt;var &lt;/span&gt;encoder = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.pngbitmapencoder.aspx"&gt;PngBitmapEncoder&lt;/a&gt;&lt;/span&gt;();
    SaveUsingEncoder(visual, fileName, encoder);
}

&lt;span style="color: blue"&gt;void &lt;/span&gt;SaveUsingEncoder(&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;visual, &lt;span style="color: blue"&gt;string &lt;/span&gt;fileName, &lt;span style="color: #2b91af"&gt;BitmapEncoder &lt;/span&gt;encoder)
{
    &lt;span style="color: #2b91af"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx"&gt;RenderTargetBitmap&lt;/a&gt; &lt;/span&gt;bitmap = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx"&gt;RenderTargetBitmap&lt;/a&gt;&lt;/span&gt;(
        (&lt;span style="color: blue"&gt;int&lt;/span&gt;)visual.ActualWidth,
        (&lt;span style="color: blue"&gt;int&lt;/span&gt;)visual.ActualHeight,
        96,
        96,
        &lt;span style="color: #2b91af"&gt;PixelFormats&lt;/span&gt;.Pbgra32);
    bitmap.Render(visual);
    &lt;span style="color: #2b91af"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapframe.aspx"&gt;BitmapFrame&lt;/a&gt; &lt;/span&gt;frame = &lt;span style="color: #2b91af"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapframe.aspx"&gt;BitmapFrame&lt;/a&gt;&lt;/span&gt;.Create(bitmap);
    encoder.Frames.Add(frame);

    &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;stream = &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Create(fileName))
    {
        encoder.Save(stream);
    }
}&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;These types are all in System.Windows.Media.Imaging.&lt;/p&gt;

&lt;h3&gt;Saving images in Silverlight 3&lt;/h3&gt;

&lt;p&gt;In Silverlight, the encoders don’t come as part of the Silverlight runtime – but fortunately there is a project on CodePlex called ImageTools (&lt;a href="http://imagetools.codeplex.com"&gt;http://imagetools.codeplex.com&lt;/a&gt;) that provides necessary support. You will need to download the following binaries and add them as references to your Silverlight project:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ICSharpCode.SharpZipLib.Silverlight &lt;/li&gt;

  &lt;li&gt;ImageTools &lt;/li&gt;

  &lt;li&gt;ImageTools.IO &lt;/li&gt;

  &lt;li&gt;ImageTools.IO.Png (only if you want .png support) &lt;/li&gt;

  &lt;li&gt;ImageTools.IO.Bmp (only if you want .bmp support) &lt;/li&gt;

  &lt;li&gt;ImageTools.Utils &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After that, you can call the ToImage() extension method on any Canvas:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;font size="2" face="Consolas"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;SaveAsPng(&lt;span style="color: #2b91af"&gt;Canvas &lt;/span&gt;canvas, &lt;span style="color: #2b91af"&gt;SaveFileDialog &lt;/span&gt;dialog)
{
    SaveToImage(canvas, dialog, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PngEncoder&lt;/span&gt;());
}

&lt;span style="color: blue"&gt;void &lt;/span&gt;SaveAsBmp(&lt;span style="color: #2b91af"&gt;Canvas &lt;/span&gt;canvas, &lt;span style="color: #2b91af"&gt;SaveFileDialog &lt;/span&gt;dialog)
{
    SaveToImage(canvas, dialog, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BmpEncoder&lt;/span&gt;());
}

&lt;span style="color: blue"&gt;void &lt;/span&gt;SaveToImage(&lt;span style="color: #2b91af"&gt;Canvas &lt;/span&gt;canvas, &lt;span style="color: #2b91af"&gt;SaveFileDialog &lt;/span&gt;dialog, &lt;span style="color: #2b91af"&gt;IImageEncoder &lt;/span&gt;encoder)
{
    &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;stream = dialog.OpenFile())
    {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;image = canvas.ToImage();
        encoder.Encode(image, stream);
    }
}&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;Since you can’t write to disk directly in Silverlight, you can pass a SaveFileDialog and use its stream, or you can obtain a stream elsewhere and pass that. The ToImage() extension method does the dirty work that we had to do ourselves in WPF.&lt;/p&gt;

&lt;p&gt;Big thanks to &lt;a href="http://imagetools.codeplex.com"&gt;http://imagetools.codeplex.com&lt;/a&gt; for their awesome library and encoders!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9906332" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/KnowledgeBase/default.aspx">KnowledgeBase</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Coding/default.aspx">Coding</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/LiveGeometry/default.aspx">LiveGeometry</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Links</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/10/05/links.aspx</link><pubDate>Mon, 05 Oct 2009 10:49:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9903106</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9903106.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9903106</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9903106</wfw:comment><description>&lt;p&gt;There are several good folks out there who regularly accumulate interesting links about all things .NET and other stuff on their blogs (cast in alphabetical order):&lt;/p&gt;  &lt;table&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://www.alvinashcraft.com/"&gt;Alvin Ashcraft&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://www.alvinashcraft.com"&gt;Alvin Ashcraft's Morning Dew&lt;/a&gt;&lt;/p&gt;          &lt;p&gt;.NET Development Resources from a Progressive.NET Perspective&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://www.arjansworld.com/"&gt;Arjan Zuidhof&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://www.arjansworld.com/"&gt;Arjan’s World&lt;/a&gt;&lt;/p&gt;          &lt;p&gt;Arjan Zuidhof’s opinionated linkblog, with a hang to Alt.NET&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://blogs.msdn.com/charlie"&gt;Charlie Calvert&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://blogs.msdn.com/charlie/default.aspx"&gt;Charlie Calvert's Community Blog&lt;/a&gt;&lt;/p&gt;          &lt;p&gt;Charlie is the C# Community Program Manager on our team and has a great series called “Community Convergence”. I hope he never runs out of &lt;a href="http://en.wikipedia.org/wiki/Roman_numerals"&gt;roman numerals&lt;/a&gt; :)&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://blog.cwa.me.uk/"&gt;Chris Alcock&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://blog.cwa.me.uk"&gt;Reflective Perspective&lt;/a&gt;&lt;/p&gt;          &lt;p&gt;The caffeine fueled thoughts of a UK Software Developer and home of ‘The Morning Brew’&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://jasonhaley.com/blog/"&gt;Jason Haley&lt;/a&gt;&lt;/p&gt;         &lt;a href="http://jasonhaley.com/blog/"&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://jasonhaley.com/blog/"&gt;Interesting Finds&lt;/a&gt;&lt;/p&gt;          &lt;p&gt;Ramblings of a .Net developer            &lt;br /&gt;.ver 3:0:0:0&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://weblogs.asp.net/scottgu/"&gt;Scott Guthrie&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;ScottGu’s &lt;a href="http://weblogs.asp.net/scottgu/archive/tags/Link+Listing/default.aspx"&gt;Link Listing&lt;/a&gt; tag &lt;/p&gt;          &lt;p&gt;Yes, ScottGu is a linkblogger!&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://spietrek.blogspot.com/"&gt;Steve Pietrek&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;a href="http://spietrek.blogspot.com/"&gt;A Continuous Learner’s weblog&lt;/a&gt;&lt;/p&gt;          &lt;p&gt;My continuous learning of .NET, C#, VB.NET, ASP.NET, Delphi, Business Intelligence, Software Design and Development, Project Management, Object Oriented Development, Unit Testing, Development Tools ramblings....&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;And since I feel a little linkbloggy myself today, here it goes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/csharpfaq/"&gt;&lt;strong&gt;C# FAQ&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; is back!&lt;/strong&gt; – Alexandra Rusina is a programming writer on our team who actually writes MSDN content for managed languages. She has taken ownership of the once-popular C# FAQ blog and has revived it to once again become an interesting and useful resource. Check our her recent posts:&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;a href="http://blogs.msdn.com/csharpfaq/archive/2009/10/01/dynamic-in-c-4-0-introducing-the-expandoobject.aspx"&gt;Dynamic in C# 4.0: Introducing the ExpandoObject&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/csharpfaq/archive/2009/09/14/generating-dynamic-methods-with-expression-trees-in-visual-studio-2010.aspx"&gt;Generating Dynamic Methods with Expression Trees in Visual Studio 2010&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/csharpfaq/archive/2009/03/25/how-to-use-linq-methods-to-compare-objects-of-custom-types.aspx"&gt;How to use LINQ methods to compare objects of custom types&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/csharpfaq/archive/2009/01/26/does-the-linq-to-objects-provider-have-built-in-performance-optimization.aspx"&gt;Does the “LINQ to Objects” provider have built-in performance optimization?&lt;/a&gt;&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;&lt;a href="http://channel9.msdn.com/shows/10-4/10-4-Episode-18-Functional-UI-Testing/"&gt;&lt;strong&gt;Functional UI Testing Channel 9 video&lt;/strong&gt;&lt;/a&gt; – &lt;a href="http://blogs.msdn.com/briankel/"&gt;Brian Keller&lt;/a&gt; does a terrific job in this compact 17-min video that shows a new possibility in VS 2010 to automatically generate code for UI tests using UIAutomation. If you’re into automated UI testing and UIAutomation, definitely check it out!&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blog.functionalfun.net/2009/06/introduction-to-ui-automation-with.html"&gt;&lt;strong&gt;An introduction to UI Automation – with spooky spirographs&lt;/strong&gt;&lt;/a&gt; – since we’re talking about UI Automation – here’s a great article on the &lt;a href="http://blog.functionalfun.net/"&gt;f(unctional) =&amp;gt; f(un)&lt;/a&gt; blog about automating Paint.NET so that it draws &lt;a href="http://en.wikipedia.org/wiki/Spirograph"&gt;spirographs&lt;/a&gt;.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://tung-sten.no-ip.com/Texts/Misc/AtmosphericPhenomena/Phenomena.htm"&gt;&lt;strong&gt;Atmospheric Phenomena&lt;/strong&gt;&lt;/a&gt; – though completely unrelated to .NET, the pics are still unbelievable!&lt;/li&gt;    &lt;li&gt;&lt;a title="http://www.n-brain.net/" href="http://www.n-brain.net"&gt;&lt;strong&gt;http://www.n-brain.net&lt;/strong&gt;&lt;/a&gt; – a collaborative IDE, seems like this idea of collaborative tools is exploding these days gaining tremendous popularity. I wish I had time to build out my &lt;a href="http://structurededitor.codeplex.com/"&gt;structured editor&lt;/a&gt; to support multiuser editing!&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/jmstall/archive/2005/02/03/366429.aspx"&gt;&lt;strong&gt;Debugging Dynamically Generated Code (Reflection.Emit)&lt;/strong&gt;&lt;/a&gt; – discovered &lt;a href="http://blogs.msdn.com/jmstall"&gt;Mike Stall&lt;/a&gt;’s great article on a way to emit necessary debugger information to tell the debugger how to map emitted code back to your source code.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.learnprolognow.org/"&gt;&lt;strong&gt;Learn Prolog Now!&lt;/strong&gt;&lt;/a&gt; – I decided to refresh my prolog skills and this is a great tutorial!&lt;/li&gt;    &lt;li&gt;&lt;a href="http://sites.google.com/site/rathereasy/eastwest"&gt;&lt;strong&gt;Eastwest&lt;/strong&gt;&lt;/a&gt; – a structure editor for O’Caml. I’m very much into language design and structured editing and this definitely looks like an interesting prototype.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.hardcodet.net/2008/12/heterogeneous-wpf-treeview"&gt;&lt;strong&gt;Organizing Heterogeneous Data on a WPF TreeView&lt;/strong&gt;&lt;/a&gt; – a great article around customizing WPF hierarchical databinding. By the way, did you know that the new Visual Studio 2010 &lt;a href="http://blogs.msdn.com/kirillosenkov/archive/2009/01/10/call-hierarchy-navigation-in-visual-studio-2010.aspx"&gt;Call Hierarchy&lt;/a&gt; feature is implemented using WPF hierarchical databinding? We use MVVM and HierarchicalDataTemplate, plus some modifications to allow the child nodes to populate on a background thread.&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903106" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Links/default.aspx">Links</category></item><item><title>Visual Studio 2010 New Editor screenshot</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/09/30/visual-studio-2010-new-editor-screenshot.aspx</link><pubDate>Thu, 01 Oct 2009 01:30:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9901553</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>18</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9901553.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9901553</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9901553</wfw:comment><description>&lt;p&gt;I’m very happy with how the &lt;a href="http://blogs.msdn.com/vseditor"&gt;Visual Studio editor&lt;/a&gt; improved since Beta1:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/VisualStudio2010NewEditorscreenshot_DA0F/image_032311b9-9cfe-43f4-a714-37e08e0ce4bd.png" width="628" height="466" /&gt; &lt;/p&gt;  &lt;p&gt;This is all WPF and includes the &lt;a href="http://blogs.msdn.com/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx"&gt;WPF 4.0 text rendering changes&lt;/a&gt; (DWrite integration). Note the new Zoom combobox in the bottom-left (which is the visual counterpart of Ctrl+ScrollWheel). Also the cross to close the tab is now located ON the tab, and not on the rightmost edge of the document. It takes about a day to get used to, but after you get used to it, it’s really awesome.&lt;/p&gt;  &lt;p&gt;I believe that the editor team has done a phenomenal job making the editor better for all of us. Note that although the screenshot was made from a remote desktop to a virtual machine, it still looks much better than in Beta1. And believe me, it is way faster and more reliable now.&lt;/p&gt;  &lt;p&gt;I’m very excited for Beta2 and can’t wait to get the bits out for you to play with!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9901553" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/VS+2010/default.aspx">VS 2010</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Random Gradient Wallpaper Generator</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/09/28/random-gradient-wallpaper-generator.aspx</link><pubDate>Mon, 28 Sep 2009 11:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9900174</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9900174.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9900174</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9900174</wfw:comment><description>&lt;P&gt;Oops, I did it again :) Created a new CodePlex project, that is.&lt;/P&gt;
&lt;P&gt;Introducing &lt;A href="http://wallpaper.codeplex.com/" mce_href="http://wallpaper.codeplex.com"&gt;&lt;STRONG&gt;http://wallpaper.codeplex.com&lt;/STRONG&gt;&lt;/A&gt; – a simple tool to generate a nice random wallpaper and display it on your desktop with just one click:&lt;/P&gt;
&lt;P&gt;&lt;IMG title=WallpaperGenerator1.png alt=WallpaperGenerator1.png src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=wallpaper&amp;amp;DownloadId=85380" mce_src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=wallpaper&amp;amp;DownloadId=85380"&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator3.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator3.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator3 border=0 alt=WallpaperGenerator3 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator3_thumb.png" width=256 height=323 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator3_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;Randomize&lt;/B&gt; - assigns random colors to all four corners &lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Set as Wallpaper&lt;/B&gt; - saves the picture to My Pictures\GradientWallpaper.bmp and sets the Windows Desktop wallpaper to this file. It will overwrite the file if it exists. &lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Save colors to text file&lt;/B&gt; - appends the RGB values of the current colors to the "colors.txt" log file in the program's directory (in case you liked the colors and want to save the colors, not the image)&lt;/LI&gt;&lt;/UL&gt;You can also click on each of the four corners and pick any color yourself. There are a total of 79228162514264337593543950336 possible wallpapers that can be generated this way. 
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator4.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator4.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator4 border=0 alt=WallpaperGenerator4 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator4_thumb.png" width=193 height=162 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator4_thumb.png"&gt;&lt;/A&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator5.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator5.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator5 border=0 alt=WallpaperGenerator5 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator5_thumb.png" width=194 height=162 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator5_thumb.png"&gt;&lt;/A&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator6.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator6.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator6 border=0 alt=WallpaperGenerator6 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator6_thumb.png" width=194 height=162 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator6_thumb.png"&gt;&lt;/A&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator7.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator7.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator7 border=0 alt=WallpaperGenerator7 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator7_thumb.png" width=194 height=162 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator7_thumb.png"&gt;&lt;/A&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator8.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator8.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator8 border=0 alt=WallpaperGenerator8 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator8_thumb.png" width=194 height=162 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator8_thumb.png"&gt;&lt;/A&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator9.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator9.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator9 border=0 alt=WallpaperGenerator9 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator9_thumb.png" width=194 height=162 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator9_thumb.png"&gt;&lt;/A&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator10.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator10.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator10 border=0 alt=WallpaperGenerator10 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator10_thumb.png" width=194 height=162 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator10_thumb.png"&gt;&lt;/A&gt;&lt;A href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator11.png" mce_href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator11.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=WallpaperGenerator11 border=0 alt=WallpaperGenerator11 src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator11_thumb.png" width=194 height=162 mce_src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/RandomGradientWallpaperGenerator_16B0/WallpaperGenerator11_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I wrote this in an evening a couple of years ago and it was just lying around, so I decided to publish it so that it doesn’t get lost. Of course, one could take WPF, &lt;A href="http://mef.codeplex.com/" mce_href="http://mef.codeplex.com"&gt;MEF&lt;/A&gt;, &lt;A href="http://bling.codeplex.com/" mce_href="http://bling.codeplex.com"&gt;Bling&lt;/A&gt;, pixel shaders and build it out into a super-extensible plug-in-based photoshop-like fractal-ray-tracing rendering wallpaper generator, but... For now, let’s stick with a simple WinForms app. But hey, it’s open source, feel free to contribute if you like ;)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9900174" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Coding/default.aspx">Coding</category></item><item><title>Dump Environment Folder Paths</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/09/27/dump-environment-folder-paths.aspx</link><pubDate>Mon, 28 Sep 2009 09:30:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9900146</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9900146.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9900146</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9900146</wfw:comment><description>&lt;p&gt;This is just a quick snippet to dump the value of Environment.GetFolderPath for all special folders on a machine (so I don’t have to write it again next time):&lt;/p&gt;  &lt;pre class="code"&gt;&lt;font size="2" face="Consolas"&gt;&lt;span style="color: blue"&gt;public static string &lt;/span&gt;DumpEnvironmentPaths()
{
    &lt;span style="color: blue"&gt;var &lt;/span&gt;paths = &lt;span style="color: #2b91af"&gt;Enum&lt;/span&gt;.GetValues(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Environment&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;SpecialFolder&lt;/span&gt;))
        .Cast&amp;lt;&lt;span style="color: #2b91af"&gt;Environment&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;SpecialFolder&lt;/span&gt;&amp;gt;()
        .Select(folder =&amp;gt; folder + &lt;span style="color: #a31515"&gt;&amp;quot; = &amp;quot; &lt;/span&gt;+ &lt;span style="color: #2b91af"&gt;Environment&lt;/span&gt;.GetFolderPath(folder))
        .Aggregate((line1, line2) =&amp;gt; line1 + &lt;span style="color: #2b91af"&gt;Environment&lt;/span&gt;.NewLine + line2);
    &lt;span style="color: blue"&gt;return &lt;/span&gt;paths;
}&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;Also, I’m using the opportunity to give &lt;a href="http://www.west-wind.com/weblog/"&gt;Rick Strahl&lt;/a&gt;’s &lt;a href="http://codepaste.net"&gt;CodePaste.NET&lt;/a&gt; service a spin: &lt;a title="http://codepaste.net/uo7zx8" href="http://codepaste.net/uo7zx8"&gt;http://codepaste.net/uo7zx8&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“CodePaste.NET is a public site for pasting snippets of code and linking to them from social network sites.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As for the code itself (envisioning potential rotten tomatoes flying my way), several things are probably worth mentioning:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;First, the code is written in a more functional style, being more explicit about its intent. I think it shows more clearly the input data and the output data, how the data flows and what operations are performed on the input data.&lt;/li&gt;

  &lt;li&gt;Second, I have a temporary local variable instead of returning the expression immediately. This is for easier debugging, because if you don’t have a temporary variable, you won’t be able to view the return value of the method easily in the debugger. With a temporary local, you can put a breakpoint on the return statement and inspect the results of the query. Someday the tools will be improved and will allow to inspect the return value of methods.&lt;/li&gt;

  &lt;li&gt;I’m using Aggregate instead of string.Join or StringBuilder because it composes better. On large data volumes, this approach is horrible because it will allocate a ridiculous amount of unnecessary intermediate strings. StringBuilder and string.Join are much more frugal in this respect, so don’t use Aggregate with strings this way. However, in this particular example, the number of strings is O(1), so I just picked the approach that composes better. Unfortunately, string.Join doesn’t compose well at all and was never intended to be used in a fluent API.&lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9900146" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/KnowledgeBase/default.aspx">KnowledgeBase</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Coding/default.aspx">Coding</category></item><item><title>Tip: Don’t enter your CodePlex credentials every time</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/09/27/tip-don-t-enter-your-codeplex-credentials-every-time.aspx</link><pubDate>Mon, 28 Sep 2009 00:10:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9900053</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9900053.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9900053</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9900053</wfw:comment><description>&lt;p&gt;I just ran across an awesome tip at &lt;a href="http://weblogs.asp.net/srkirkland/"&gt;Scott’s blog&lt;/a&gt; that is going to save me a whole lot of time: &lt;a href="http://weblogs.asp.net/srkirkland/archive/2009/09/24/save-your-codeplex-repository-credentials.aspx"&gt;Save Your Codeplex Repository Credentials&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I was entering my username and password everytime I connected to a CodePlex TFS server. Now I don’t have to!&lt;/p&gt;  &lt;p&gt;P.S. To make this work on XP, go to Control Panel –&amp;gt; User Accounts –&amp;gt; click your account –&amp;gt; in the leftmost pane click &lt;strong&gt;Manage My Network Passwords&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/TipDontenteryourCodePlexcredentialsevery_C7D3/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/TipDontenteryourCodePlexcredentialsevery_C7D3/image_thumb.png" width="524" height="395" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/TipDontenteryourCodePlexcredentialsevery_C7D3/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/kirillosenkov/WindowsLiveWriter/TipDontenteryourCodePlexcredentialsevery_C7D3/image_thumb_1.png" width="524" height="397" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9900053" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/KnowledgeBase/default.aspx">KnowledgeBase</category></item><item><title>ColorPicker Control for WPF/Silverlight</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/09/25/colorpicker-control-for-wpf-silverlight.aspx</link><pubDate>Sat, 26 Sep 2009 01:06:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9899771</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9899771.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9899771</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9899771</wfw:comment><description>&lt;p&gt;A while back I was looking around for a color picker control for &lt;a href="http://livegeometry.codeplex.com/"&gt;Live Geometry&lt;/a&gt;. The ColorPicker from &lt;a title="http://silverlightcontrib.codeplex.com" href="http://silverlightcontrib.codeplex.com"&gt;http://silverlightcontrib.codeplex.com&lt;/a&gt; was exactly what I was looking for:&lt;/p&gt; &lt;object data="data:application/x-silverlight," type="application/x-silverlight-2" width="200" height="220"&gt; 	&lt;param name="source" value="http://guilabs.de/xap/ColorPickerDemo1.xap" /&gt; 	&lt;param name="background" value="white" /&gt; 	&lt;param name="minRuntimeVersion" value="2.0.31005.0" /&gt; 	&lt;param name="autoUpgrade" value="true" /&gt; 	&lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt; 	&lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt; 	&lt;/a&gt; &lt;/object&gt;  &lt;p&gt;&lt;font size="1"&gt;(live preview needs Silverlight 3.0)&lt;/font&gt;&lt;/p&gt;  &lt;h3&gt;Using the control in your code&lt;/h3&gt;  &lt;p&gt;I just took the source from CodePlex and embedded it in my project. You need 5 files:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://guilabs.de/images/LiveWriter/ColorPickerControlforWPFSilverlight_FF1C/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://guilabs.de/images/LiveWriter/ColorPickerControlforWPFSilverlight_FF1C/image_thumb.png" width="222" height="161" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Alternatively, you can reference the binary which you can download from the &lt;a href="http://silverlightcontrib.codeplex.com/"&gt;SilverlightContrib CodePlex project site&lt;/a&gt;. Pay attention that generic.xaml contains the template for the control, so don’t forget the xaml. The control will work just fine with WPF and Silverlight, which is really a great thing, especially if you’re multitargeting.&lt;/p&gt;  &lt;p&gt;To include the control in your application, here’s the basic code:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;sc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ColorPicker &lt;/span&gt;&lt;span style="color: red"&gt;SelectedColor&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;LightGreen&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Don’t forget to add an XML namespace:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;sc&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:SilverlightContrib.Controls&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;h3&gt;How does the gradient work?&lt;/h3&gt;

&lt;p&gt;The source code for this control is very good for educational purposes. For instance, I had no idea how they create the big gradient for every possible hue. Well, it’s genius and it’s simple. In generic.xaml:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Canvas &lt;/span&gt;&lt;span style="color: red"&gt;Canvas.Top&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Canvas.Left&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;20&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ColorSample&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;180&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;180&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Fill&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Red&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WhiteGradient&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;IsHitTestVisible&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;180&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;180&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush &lt;/span&gt;&lt;span style="color: red"&gt;StartPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0,0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;EndPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1,0&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#ffffffff&amp;quot;/&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#00ffffff&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;BlackGradient&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;IsHitTestVisible&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;180&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;180&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush &lt;/span&gt;&lt;span style="color: red"&gt;StartPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0,1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;EndPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0, 0&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#ff000000&amp;quot;/&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#00000000&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Rectangle&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Canvas &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;SampleSelector&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;IsHitTestVisible&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;10&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;10&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Canvas.Left&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;100&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Canvas.Top&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;96&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Ellipse &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;10&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;10&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;StrokeThickness&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;3&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Stroke&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#FFFFFFFF&amp;quot;/&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Ellipse &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;10&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;10&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;StrokeThickness&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Stroke&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#FF000000&amp;quot;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Canvas&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Canvas&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This canvas contains layers like in a cake. ZIndex of objects is stacked bottom to top, so the solid rectangle with initially red background is on the bottom.&lt;/p&gt;

&lt;p&gt;Above it, there is a horizontal white gradient fill, completely white on the left and completely transparent on the right.&lt;/p&gt;

&lt;p&gt;Above it, there is a vertical black gradient fill, completely black on the bottom and completely transparent on the top.&lt;/p&gt;

&lt;p&gt;As these gradients overlay, the transparency over the initial solid background creates the desired effect – the actual color is in top-right, where both gradients are 100% transparent. The white spot is in top-left, where the white gradient is most intense and black gradient fades out. Same for the black edge of the gradient.&lt;/p&gt;

&lt;p&gt;Also, it is well worth studying how the template is written – I learned a lot from this sample.&lt;/p&gt;

&lt;h3&gt;My fixes&lt;/h3&gt;

&lt;p&gt;Since I conveniently borrowed the source code for my project, I did several fixes for my own purposes. Ideally I should contribute the fixes back to SilverlightContrib, but I can never get around to it.&lt;/p&gt;

&lt;p&gt;First of all, I reordered the two StackPanels in the template so that the actual selected color is on top. I also made it collapsible and collapsed by default. You can expand the control by clicking it like a combobox. Unlike a combobox, you have to explicitly click the color area to collapse it again.&lt;/p&gt;
&lt;object data="data:application/x-silverlight," type="application/x-silverlight-2" width="200" height="220"&gt;
	&lt;param name="source" value="http://guilabs.de/xap/ColorPickerDemo2.xap" /&gt;
	&lt;param name="background" value="white" /&gt;
	&lt;param name="minRuntimeVersion" value="2.0.31005.0" /&gt;
	&lt;param name="autoUpgrade" value="true" /&gt;
	&lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt;
	&lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt;
	&lt;/a&gt;
&lt;/object&gt;

&lt;p&gt;I’ve enabled this by adding an Expanded property:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public bool &lt;/span&gt;Expanded
{
    &lt;span style="color: blue"&gt;get
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;return &lt;/span&gt;m_chooserArea.Visibility == &lt;span style="color: #2b91af"&gt;Visibility&lt;/span&gt;.Visible;
    }
    &lt;span style="color: blue"&gt;set
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;var &lt;/span&gt;visibility = &lt;span style="color: blue"&gt;value &lt;/span&gt;? &lt;span style="color: #2b91af"&gt;Visibility&lt;/span&gt;.Visible : &lt;span style="color: #2b91af"&gt;Visibility&lt;/span&gt;.Collapsed;
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(m_chooserArea.Visibility == visibility)
        {
            &lt;span style="color: blue"&gt;return&lt;/span&gt;;
        }
        m_chooserArea.Visibility = visibility;
    }
}&lt;/pre&gt;

&lt;p&gt;When clicking on the color area, I just call Enabled = !Enabled to toggle it and it does the magic for me. The default value for this is obviously the default visibility of m_chooserArea, which is specified in XAML template (Visibility=”Visible” to set to true by default).&lt;/p&gt;

&lt;p&gt;Other fixes are not as interesting. I fixed a division by zero in ColorSpace.ConvertRgbToHsv (they had h = 60 * (g - b) / (max - min); and didn’t check if min == max). There are a couple of other things which I don’t remember off the top of my head. I’d have to view TFS history to remember what those were. If you’re willing to help and incorporate these fixes to the original project, I’ll dig this up, just let me know :)&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Both &lt;a href="http://blogs.msdn.com/saraford/"&gt;Sara Ford&lt;/a&gt; and myself agree that this control deserves both thumbs up:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://guilabs.de/images/LiveWriter/ColorPickerControlforWPFSilverlight_FF1C/image_3.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://guilabs.de/images/LiveWriter/ColorPickerControlforWPFSilverlight_FF1C/image_thumb_3.png" width="735" height="120" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899771" width="1" height="1"&gt;</description></item><item><title>Reflection with dynamic</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/09/15/reflection-with-dynamic.aspx</link><pubDate>Wed, 16 Sep 2009 06:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9895666</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9895666.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9895666</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9895666</wfw:comment><description>&lt;P&gt;This past summer the Visual C# IDE team was fortunate enough to have &lt;A href="http://www.paulvanbrenk.com/" mce_href="http://www.paulvanbrenk.com/"&gt;Paul van Brenk&lt;/A&gt; intern with us. Paul is a great guy and an experienced .NET developer from &lt;A href="http://www.bing.com/maps/?v=2&amp;amp;where1=Rotterdam%2C%20Netherlands" mce_href="http://www.bing.com/maps/?v=2&amp;amp;where1=Rotterdam%2C%20Netherlands"&gt;Rotterdam, Netherlands&lt;/A&gt;, who is interested in Azure, cloud computing and many other things. He also happens to be one of the contributors for &lt;A href="http://dasblog.info/" mce_href="http://dasblog.info/"&gt;dasBlog&lt;/A&gt;, which I think is seriously cool.&lt;/P&gt;
&lt;P&gt;Paul and I were sharing an office during his internship and I was the “coach”, i.e. the guy who gets to answer all intern’s questions and helps figure things out :)&lt;/P&gt;
&lt;P&gt;Anyway, once we were talking about how to simplify the mess of calling private members using reflection and dynamic came into conversation. So Paul went ahead and wrote some C# 4.0 code that greatly simplifies calling private members using dynamic. Check out his blog: &lt;A title=http://www.paulvanbrenk.com/blog/2009/05/30/UsingDynamicForEvil.aspx href="http://www.paulvanbrenk.com/blog/2009/05/30/UsingDynamicForEvil.aspx" mce_href="http://www.paulvanbrenk.com/blog/2009/05/30/UsingDynamicForEvil.aspx"&gt;&lt;STRONG&gt;http://www.paulvanbrenk.com/blog/2009/05/30/UsingDynamicForEvil.aspx&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;There are several things I’d like to shed more light on.&lt;/P&gt;
&lt;H3&gt;Dynamic usage scenarios&lt;/H3&gt;
&lt;P&gt;It’s a common misconception that dynamic can only be used for narrow interop scenarios. People came up with ways to use dynamic in a lot more scenarios.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://haacked.com/" mce_href="http://haacked.com/"&gt;Phil Haack&lt;/A&gt; has a couple of nice posts on dynamic definitely worth reading: &lt;A href="http://haacked.com/archive/2009/08/26/method-missing-csharp-4.aspx" mce_href="http://haacked.com/archive/2009/08/26/method-missing-csharp-4.aspx"&gt;Fun With Method Missing and C# 4&lt;/A&gt; and &lt;A href="http://haacked.com/archive/2009/08/31/7-stages-of-language-keyword-grief.aspx" mce_href="http://haacked.com/archive/2009/08/31/7-stages-of-language-keyword-grief.aspx"&gt;7 Stages of new language keyword grief&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://mark.michaelis.net/blog/" mce_href="http://mark.michaelis.net/blog/"&gt;Mark Michaelis&lt;/A&gt; has a great example of dynamic XML here: &lt;A title=http://mark.michaelis.net/Blog/DynamicallyTypedObjectsWithC40.aspx href="http://mark.michaelis.net/Blog/DynamicallyTypedObjectsWithC40.aspx" mce_href="http://mark.michaelis.net/Blog/DynamicallyTypedObjectsWithC40.aspx"&gt;http://mark.michaelis.net/Blog/DynamicallyTypedObjectsWithC40.aspx&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;Paul van Brenk blogs about dynamic reflection as I mentioned above: &lt;A title=http://www.paulvanbrenk.com/blog/2009/05/30/UsingDynamicForEvil.aspx href="http://www.paulvanbrenk.com/blog/2009/05/30/UsingDynamicForEvil.aspx" mce_href="http://www.paulvanbrenk.com/blog/2009/05/30/UsingDynamicForEvil.aspx"&gt;http://www.paulvanbrenk.com/blog/2009/05/30/UsingDynamicForEvil.aspx&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;A common theme emerges from such usages: delay the name resolution (binding) to runtime. Instead of hardcoding the symbols known to compiler, we just specify source strings that have to be used at a later stage at runtime for lookup.&lt;/P&gt;
&lt;P&gt;Dynamic gives you nicer syntax to express member calls – you express them in your code using usual C# syntax (but without type checking), and the compiler does the heavy lifting of “quoting” the code down to the runtime. If you &lt;A href="http://blogs.msdn.com/cburrows/archive/2008/10/27/c-dynamic.aspx" mce_href="http://blogs.msdn.com/cburrows/archive/2008/10/27/c-dynamic.aspx"&gt;inspect the generated code&lt;/A&gt;, you will see that the compiler is taking your neat member call syntax and generating a complex call site data structure that contains metainformation about the call.&lt;/P&gt;
&lt;H3&gt;How the language design team designed the dynamic feature&lt;/H3&gt;
&lt;P&gt;From previous versions of C# you will notice that the language design team is clever when adding new features. They don’t just hardcode a feature into the language, they define an interface and implement the feature against that interface. Not literally, mind you. On the contrary, they rather use duck-typing in most cases, but still there is a contract defined somewhere and the feature works against that contract. Let me give a couple of examples:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;foreach – they could have added foreach just to arrays. Instead, they “designed against an interface” and said: foreach will work against any IEnumerable implementation. Moreover, the contract of the feature is actually broader and is specified using duck-typing and not an explicit interface. foreach actually works against anything that has a GetEnumerator method, it does not have to implement IEnumerable. The extensibility here is that you can plug-in your own enumerator whatever it is and foreach will work just fine with it.&lt;/LI&gt;
&lt;LI&gt;LINQ – again, the language design team said: query syntax will just translate into a well-defined set of methods (Select, Where, etc.). The extensibility here is that you can define your own Select, Where, etc. and LINQ will rewrite the query expressions against your own methods – the queries will continue to just work with your own implementation of the query pattern.&lt;/LI&gt;
&lt;LI&gt;dynamic – and here, in C# 4.0, they didn’t just add dynamic. They defined an abstraction layer (an interface) that allows you to plug in your own implementation and the feature (dynamic) will work fine with it.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;In other words, they encapsulated an object with runtime callable members into an interface (&lt;A href="http://msdn.microsoft.com/en-us/library/system.dynamic.idynamicmetaobjectprovider(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.dynamic.idynamicmetaobjectprovider(VS.100).aspx"&gt;IDynamicMetaObjectProvider&lt;/A&gt;) and provided default base implementation (&lt;A href="http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject(VS.100).aspx"&gt;DynamicObject&lt;/A&gt;). What this gives you is the ability to plug in your own implementation and dynamic will work against it.&lt;/P&gt;
&lt;P&gt;Effectively, this means that &lt;EM&gt;you can intercept member calls on any object, if these calls are dynamic&lt;/EM&gt;. The secret of “abusing” dynamic is to use member call syntax for stuff other than calling a method. By redefining DynamicObject members you handle member calls in any way you want (usually some sort of lookup by string) – dictionary lookup, XML element and attribute lookup, reflection MemberInfo lookup, and so on.&lt;/P&gt;
&lt;P&gt;Now whether this all is good or bad is a totally separate discussion.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9895666" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/VS+2010/default.aspx">VS 2010</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/C_2300_+4.0/default.aspx">C# 4.0</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Links/default.aspx">Links</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Coding/default.aspx">Coding</category></item><item><title>First videos of the structured editor prototype</title><link>http://blogs.msdn.com/kirillosenkov/archive/2009/09/08/first-videos-of-the-structured-editor-prototype.aspx</link><pubDate>Wed, 09 Sep 2009 08:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9892958</guid><dc:creator>Kirill Osenkov</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/kirillosenkov/comments/9892958.aspx</comments><wfw:commentRss>http://blogs.msdn.com/kirillosenkov/commentrss.aspx?PostID=9892958</wfw:commentRss><wfw:comment>http://blogs.msdn.com/kirillosenkov/rsscomments.aspx?PostID=9892958</wfw:comment><description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size=-2&gt;Disclaimer: the structured editor work described in my posts is unrelated to my work at Microsoft. Everything shown is my personal research done as part of my MSc thesis during 2004-2007. Also, it’s not ready for real use and does not cover all the features of even C# 1.0. It’s a concept prototype and work in progress.&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;H2&gt;Introduction&lt;/H2&gt;
&lt;P&gt;As part of my &lt;A href="http://www.osenkov.com/diplom/" mce_href="http://www.osenkov.com/diplom/"&gt;research&lt;/A&gt; back in &lt;A href="http://www.tu-cottbus.de/btu/en.html" mce_href="http://www.tu-cottbus.de/btu/en.html"&gt;school&lt;/A&gt; I was building an experimental structured editor for C#. Now I’ve decided to publish the sources and binaries on CodePlex:&lt;/P&gt;
&lt;P&gt;&lt;A title=http://structurededitor.codeplex.com/ href="http://structurededitor.codeplex.com/" mce_href="http://structurededitor.codeplex.com"&gt;&lt;STRONG&gt;http://structurededitor.codeplex.com&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;A detailed discussion of structured editors deserves a separate post, which is coming soon. For now, to give a better idea of how the editor works, I’ve recorded six short videos showing the different features below. If your blog reader doesn’t support iframes, I recommend you view this post in the browser.&lt;/P&gt;
&lt;H2&gt;What is a structured editor?&lt;/H2&gt;
&lt;P&gt;Programs are represented as text by most code editors. &lt;A href="http://en.wikipedia.org/wiki/Structure_editor" mce_href="http://en.wikipedia.org/wiki/Structure_editor"&gt;Structured editors&lt;/A&gt;, on the contrary, directly display the syntax tree of a program on screen and allow the user to manipulate the tree directly (think MVC: program parse tree is a model, the editor displays a view of it):&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.osenkov.com/diplom/contents/1/3/index_clip_image004.gif" mce_src="http://www.osenkov.com/diplom/contents/1/3/index_clip_image004.gif"&gt; &lt;/P&gt;
&lt;P&gt;This way the visual layout better illustrates the structure of the program and allows for atomic operations on the language constructs. A structured editor lets developers avoid syntax errors and concentrate on the meaning of the program instead of formatting.&lt;/P&gt;
&lt;H2&gt;1. Introduction&lt;/H2&gt;
&lt;DIV&gt;&lt;IFRAME height=730 src="http://guilabs.de/video/Intro.html" frameBorder=0 width=790 mce_src="http://guilabs.de/video/Intro.html"&gt;   
&lt;p&gt;To see the video the page has to be viewed in a web-browser that supports iframes.&lt;/p&gt;

&lt;/IFRAME&gt;&lt;/DIV&gt;
&lt;H2&gt;2. Editing&lt;/H2&gt;
&lt;DIV&gt;&lt;IFRAME height=760 src="http://guilabs.de/video/Editing.html" frameBorder=0 width=800 mce_src="http://guilabs.de/video/Editing.html"&gt;   
&lt;p&gt;To see the video the page has to be viewed in a web-browser that supports iframes.&lt;/p&gt;

&lt;/IFRAME&gt;&lt;/DIV&gt;
&lt;DIV&gt;You will notice that there is no intellisense and coloring at the expression level – I did build a SharpDevelop add-in that hosts the structured editor control inside the SharpDevelop project system (DOM), but these videos were recorded on a stand-alone version of the structured editor control hosted inside an empty windows form. Also the support at the expression level is rudimentary, because so far I’ve concentrated the most at declaration level (namespaces, types, members) and statement level (except for single-line statements such as assignments).&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;3. Drag &amp;amp; Drop Support&lt;/H2&gt;
&lt;DIV&gt;&lt;IFRAME height=800 src="http://guilabs.de/video/DragDrop.html" frameBorder=0 width=820 mce_src="http://guilabs.de/video/DragDrop.html"&gt;   
&lt;p&gt;To see the video the page has to be viewed in a web-browser that supports iframes.&lt;/p&gt;

&lt;/IFRAME&gt;&lt;/DIV&gt;
&lt;H2&gt;4. No Parser Means Less Syntax&lt;/H2&gt;
&lt;DIV&gt;&lt;IFRAME height=560 src="http://guilabs.de/video/LessSyntax.html" frameBorder=0 width=790 mce_src="http://guilabs.de/video/LessSyntax.html"&gt;   
&lt;p&gt;To see the video the page has to be viewed in a web-browser that supports iframes.&lt;/p&gt;

&lt;/IFRAME&gt;&lt;/DIV&gt;
&lt;H2&gt;5. Properties&lt;/H2&gt;
&lt;DIV&gt;&lt;IFRAME height=580 src="http://guilabs.de/video/Properties.html" frameBorder=0 width=780 mce_src="http://guilabs.de/video/Properties.html"&gt;   
&lt;p&gt;To see the video the page has to be viewed in a web-browser that supports iframes.&lt;/p&gt;

&lt;/IFRAME&gt;&lt;/DIV&gt;
&lt;H2&gt;6. Modifiers&lt;/H2&gt;
&lt;DIV&gt;&lt;IFRAME height=550 src="http://guilabs.de/video/Modifiers.html" frameBorder=0 width=730 mce_src="http://guilabs.de/video/Modifiers.html"&gt;   
&lt;p&gt;To see the video the page has to be viewed in a web-browser that supports iframes.&lt;/p&gt;

&lt;/IFRAME&gt;&lt;/DIV&gt;
&lt;H2&gt;Background&lt;/H2&gt;
&lt;P&gt;&lt;A href="http://en.wikipedia.org/wiki/Structure_editor" mce_href="http://en.wikipedia.org/wiki/Structure_editor"&gt;Structured editing&lt;/A&gt; is a topic surrounded with scepticism and controversy for the past 20-30 years. Some argue that directly editing the AST on screen is inflexible and inconvenient, because the constraints of always having a correct program restrict the programmer way too much. Others expect structured editors to be more helpful than text editors because the user operates atomically and precisely on the language constructs, concentrating on the semantics and not on syntax.&lt;/P&gt;
&lt;P&gt;In summer 2004, my professor &lt;A href="http://www-pscb.informatik.tu-cottbus.de/mitarbeiter/bachmann/pb.htm" mce_href="http://www-pscb.informatik.tu-cottbus.de/mitarbeiter/bachmann/pb.htm"&gt;Peter Bachmann&lt;/A&gt; initiated a student research project - we started building a structured editor for C#. I took part because I was deeply persuaded that good structured editors can actually be built, and it was challenging to go and find out for myself. After the original project was over, I took over the basic prototype and evolved it further to the state it is today.&lt;/P&gt;
&lt;P&gt;As one of numerous confirmations for my thoughts, in 2004, &lt;A href="http://wesnerm.blogs.com/" mce_href="http://wesnerm.blogs.com/"&gt;Wesner Moise&lt;/A&gt; &lt;A href="http://wesnerm.blogs.com/net_undocumented/2004/06/whidbey_may_mis.html" mce_href="http://wesnerm.blogs.com/net_undocumented/2004/06/whidbey_may_mis.html"&gt;wrote&lt;/A&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;...I see a revolution brewing within the next three years in the way source code is written.&lt;/P&gt;
&lt;P&gt;Text editors are going to go away (for source code, that is)! Don't get me wrong, source code will still be in text files. However, future code editors will parse the code directly from the text file and will be display in a concise, graphical and nicely presented view with each element in the view representing a parse tree node. ...&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I remember how I agreed with this! After three years, in 2007, the prototype implementation was ready - it became the result of my &lt;A href="http://www.osenkov.com/diplom/" mce_href="http://www.osenkov.com/diplom/"&gt;master's thesis&lt;/A&gt;. I still agree with what Wesner was envisioning in 2004 - with one exception. Now I believe that structured editors shouldn't (and can't) be a revolution - fully replacing text editors is a bad thing to do. Instead, structured editors should complement text editors to provide yet another view on the same source tree (internal representation, or AST).&lt;/P&gt;
&lt;H2&gt;My conclusions about structured editors&lt;/H2&gt;
&lt;OL&gt;
&lt;LI&gt;Text-based editors aren’t going away anytime soon.&lt;/LI&gt;
&lt;LI&gt;Structured editors can only succeed by evolution, not revolution – hybrid approach and ability to toggle between text and structure is the way to go.&lt;/LI&gt;
&lt;LI&gt;The main difficulty with structured editors is getting the usability right.&lt;/LI&gt;
&lt;LI&gt;The right approach is solving all the numerous little problems one by one – find a solution for every situation where a text editor is better (from my experience, for any advantage of a text editor, a good structured solution can be found).&lt;/LI&gt;
&lt;LI&gt;You need a graphical framework with auto-layout such as WPF to build a structured editor.&lt;/LI&gt;
&lt;LI&gt;Don’t try to build a universal editor editor that can edit itself – this approach is too complex. Take a specific language and build a hardcoded editor for this language first. Only after you’ve built 2-3 successful editors, it makes sense to generalize and build a universal editor or an editor generator.&lt;/LI&gt;
&lt;LI&gt;Compilers shouldn’t be a black box, but expose the data structures as a public API surface.&lt;/LI&gt;
&lt;LI&gt;Syntax trees should be observable so that the editor can databind to them.&lt;/LI&gt;
&lt;LI&gt;Traditional expression editor should be hostable inside a structured editor for single-line statements and expressions.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;As a result of my work, I'm convinced that structured editors actually are, in some situations, more convenient than text editors and providing the programmer with two views on the code to choose from would be a benefit. Just like Visual Studio Class Designer - those who want to use it, well, just use it, and the rest continues to happily use the text editor. All these views should co-exist to provide the programmer with a richer palette of tools to chooce from.&lt;/P&gt;
&lt;P&gt;Hence, my first important conclusion. &lt;EM&gt;A program's internal representation (the AST) should be observable to allow the MVC architecture - many views on the same internal code model.&lt;/EM&gt; With MVC, all views will be automatically kept in sync with the model. This is where for example something like WPF data-binding would come in handy.&lt;/P&gt;
&lt;P&gt;As for the structured editor itself - it is still a work in progress and I still hope to create a decent complement for text editors. It has to be usable and there are still a lot problems to solve before I can say: "Here, this editor is at least as good as the text editor". But I managed to solve so many challenging problems already, that I'm optimistic about the future.&lt;/P&gt;
&lt;H2&gt;Current implementation&lt;/H2&gt;
&lt;P&gt;The current implementation edits a substantial subset of C# 1.0 - namespaces, types, members (except events), and almost all statements. If you're interested, you can &lt;STRONG&gt;read more&lt;/STRONG&gt; at &lt;A href="http://www.guilabs.net/" mce_href="http://www.guilabs.net"&gt;http://www.guilabs.net&lt;/A&gt; and &lt;A href="http://www.osenkov.com/diplom" mce_href="http://www.osenkov.com/diplom"&gt;www.osenkov.com/diplom&lt;/A&gt; - those are two sites I built to tell the world about my efforts. I also accumulate my links about structured editing here: &lt;A href="http://delicious.com/KirillOsenkov/StructuredEditors" mce_href="http://delicious.com/KirillOsenkov/StructuredEditors"&gt;http://delicious.com/KirillOsenkov/StructuredEditors&lt;/A&gt;&lt;/P&gt;
&lt;H2&gt;More languages&lt;/H2&gt;
&lt;P&gt;It turned out that it makes sense to build structured editors not only for C#, but for other languages as well - XML, HTML, &lt;A href="http://www.e-pig.org/" mce_href="http://www.e-pig.org/"&gt;Epigram&lt;/A&gt;, &lt;A href="http://nemerle.org/" mce_href="http://nemerle.org/"&gt;Nemerle&lt;/A&gt;, etc. That is why, at the very beginning, the whole project was split in two parts - the editor framework and the C# editor built on top of it.&lt;/P&gt;
&lt;H2&gt;Links&lt;/H2&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;A href="http://structurededitor.codeplex.com/" mce_href="http://structurededitor.codeplex.com"&gt;http://structurededitor.codeplex.com&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://guilabs.net/" mce_href="http://guilabs.net"&gt;http://guilabs.net&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.osenkov.com/diplom" mce_href="http://www.osenkov.com/diplom"&gt;http://www.osenkov.com/diplom&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://delicious.com/KirillOsenkov/StructuredEditors" mce_href="http://delicious.com/KirillOsenkov/StructuredEditors"&gt;http://delicious.com/KirillOsenkov/StructuredEditors&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;If you want to know more, or if you want to share your opinion on this, please let me know. I welcome any feedback! Thanks!&lt;/P&gt;&lt;A href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.msdn.com%2fkirillosenkov%2farchive%2f2009%2f09%2f08%2ffirst-videos-of-the-structured-editor-prototype.aspx"&gt;&lt;IMG border=0 alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.msdn.com%2fkirillosenkov%2farchive%2f2009%2f09%2f08%2ffirst-videos-of-the-structured-editor-prototype.aspx"&gt;&lt;/A&gt; &lt;A href="http://dotnetshoutout.com/First-videos-of-the-structured-editor-prototype" rev=vote-for&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.msdn.com%2Fkirillosenkov%2Farchive%2F2009%2F09%2F08%2Ffirst-videos-of-the-structured-editor-prototype.aspx"&gt;&lt;/A&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9892958" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/Links/default.aspx">Links</category><category domain="http://blogs.msdn.com/kirillosenkov/archive/tags/StructuredEditor/default.aspx">StructuredEditor</category></item></channel></rss>