<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:a10="http://www.w3.org/2005/Atom" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>NetFXHarmonics (Online Home of David Betz [MVP])</title><description>David Betz' Home for AJAX, Silverlight, and .NET Technology, Architecture, and Elegance</description><category>Training</category><category>Firefox</category><category>C#</category><category>Exceptions</category><category>WCF</category><category>WPF</category><category>ASP.NET</category><category>AJAX</category><category>XHTML/CSS</category><category>LLBLGen Pro</category><category>XAG</category><category>Silverlight</category><category>Videos</category><category>Services</category><category>Projects</category><category>Themelia</category><category>Debugging</category><creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/FXHarmonics" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><author>dfb@davidbetz.net</author><title>NetFXHarmonics Code Annotation Format</title><description>&lt;p&gt;If you look at any of my open-source projects or even the Themelia source code, you will see that I use a special type of coding annotation.&amp;#160; The annotation format I designed (based on the designs of Sky Morey at &lt;a href="http://www.digitalev.com/"&gt;Digital Evolution Group&lt;/a&gt;) is intended to maximize code readability and understandability.&amp;#160; The format is NOT a coding standard, but just what it says: an annotation format.&lt;/p&gt;  &lt;p&gt;What’s that means?&amp;#160; Essentially when you are reading code you are constantly parsing all the symbols that you see.&amp;#160; Your brain can only work so fast, though, and some things have a higher parsing latency than others.&amp;#160; For example, VB code is incredibly verbose and uses long symbols to representing even the smallest things.&amp;#160; It will use the symbol “Then” where C# will use the symbol “}” (to some it may seem odd to think of a word as a symbol, but that’s all it is—you never read ever letter of a word you know.&amp;#160; If you know the word, your brain treats it as a symbol, not a series of symbols.)&amp;#160; It will also use two different character sets (what we call upper case and lower case) interchangeably, thus ever increasing the latency.&amp;#160; Though C# was designed with extremely low latency in mind, it, like all other languages, still has excess latency.&lt;/p&gt;  &lt;p&gt;Thus, my code annotation format comes on the scene to make mental code parsing extremely fast.&amp;#160; It covers everything from how to case comments, when NOT to write comments, when to add metadata to class members, and how to deal with line breaks (the cardinal rule of the format!)&amp;#160; Most importantly, every annotation rule has an extensive commentary explaining why the rule exists and what value it provides in the long run.&lt;/p&gt;  &lt;p&gt;Now, as with ALL THINGS EVERYWHERE, when you first start to apply it, it’s going to seem odd and it will slow you down at first.&amp;#160; After time, however, you will become extremely efficient at it and your code readability should dramatically improve.&amp;#160; When this is used in groups, it should seriously lower decrease the time it takes to read and understand the purpose of code.&lt;/p&gt;  &lt;p&gt;You can view the NetFXHarmonics Code Annotation Format at &lt;a title="http://www.netfxharmonics.com/document/code/format" href="http://www.netfxharmonics.com/document/code/format"&gt;http://www.netfxharmonics.com/document/code/format&lt;/a&gt;.&lt;/p&gt;</description><pubDate>Fri, 24 Apr 2009 11:30:07 -0500</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/NetFXHarmonics-Code-Annotation-Format" /></item><item><author>dfb@davidbetz.net</author><category>Silverlight</category><title>New Silverlight 3 Features</title><description>&lt;p&gt;Though I’m a member of the Silverlight 3 Early Adopter’s Program (and thus have been getting weekly builds of Silverlight long before the public beta), I’m probably not going to be writing anything about the new features.&amp;#160; This isn’t because Silverlight 3 is boring, but, rather, because I have a strict policy of never doing something that other’s are already doing.&amp;#160; So, I would like to direct your attention to a few web sites showing the awesome provided by Silverlight 3 (and you won’t find business-application boringness here).&lt;/p&gt;  &lt;p&gt;First, Tim Huerer has a nice post giving a very quick rundown of the new features:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://timheuer.com/blog/archive/2009/03/18/silverlight-3-whats-new-a-guide.aspx"&gt;http://timheuer.com/blog/archive/2009/03/18/silverlight-3-whats-new-a-guide.aspx&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Second, Jeff Prosise’s blog shows some of the cooler features of Silverlight 3.&amp;#160; Maybe it’s just because I absolutely HATE business application development, but I find Jeff’s blog to be 100x more interesting than the “how to write use X to write your boring line-of-business application.”&amp;#160; His work is also not for the naive or faint of heart.&amp;#160; Instead, it’s for professional developers (i.e. the extremely rare people who aren’t afraid to do things the right way.)&amp;#160; If Jeff adds more stuff, I’ll add them to this list.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/27/silverlight-3-s-new-element-data-binding.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/27/silverlight-3-s-new-element-data-binding.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/20/silverlight-3-s-new-perspective-transform.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/20/silverlight-3-s-new-perspective-transform.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/23/silverlight-3-s-new-writeablebitmap.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/23/silverlight-3-s-new-writeablebitmap.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/25/silverlight-3-s-new-pixel-shaders.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/25/silverlight-3-s-new-pixel-shaders.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/26/silverlight-3-s-new-animation-easing.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/26/silverlight-3-s-new-animation-easing.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/29/silverlight-3-s-new-gpu-acceleration.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/29/silverlight-3-s-new-gpu-acceleration.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/05/silverlight-3-s-new-out-of-browser-applications.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/05/silverlight-3-s-new-out-of-browser-applications.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/06/silverlight-3-s-new-assembly-caching.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/06/silverlight-3-s-new-assembly-caching.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/07/silverlight-3-s-new-navigation-framework.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/07/silverlight-3-s-new-navigation-framework.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/08/silverlight-3-s-new-style-enhancements.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/08/silverlight-3-s-new-style-enhancements.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2008/04/12/control-interop-silverlight-style.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2008/04/12/control-interop-silverlight-style.aspx&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Finally, you can always head over to the Mix ‘09 web site and watch some Silverlight 3 (and 2) videos.&amp;#160; Most of them also have PowerPoint files associated with them.&amp;#160; Personally, I can’t stand the torture of listening to someone take 30 minutes to say something that I can ready in 3 minutes.&amp;#160; That’s one reason I turned Microsoft down when they asked me to turn my &lt;a href="http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2"&gt;Understanding WCF Services in Silverlight 2&lt;/a&gt; into a talk at Mix.&amp;#160; Boring.&amp;#160; Here’s the Mix link:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://videos.visitmix.com/MIX09/Tags/Silverlight"&gt;http://videos.visitmix.com/MIX09/Tags/Silverlight&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;See also &lt;a href="http://videos.visitmix.com/MIX09/T14F"&gt;What's New in Microsoft Silverlight 3&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;See also &lt;a href="http://videos.visitmix.com/MIX09/T45F"&gt;Building Out of Browser Experiences with Microsoft Silverlight 3&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;</description><pubDate>Mon, 20 Apr 2009 22:29:13 -0500</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/New-Silverlight-3-Features" /></item><item><author>dfb@davidbetz.net</author><category>Silverlight</category><title>Jeff Prosise&amp;rsquo;s Silverlight Tips</title><description>&lt;p&gt;This post may be completely meaningless to most of the developers out there as it deals with my type of development: non-business application development.&amp;#160; More specifically, Jeff Prosise of Wintellect (the Navy SEALs of .NET) has posted a few really nice tips and tricks for Silverlight development.&amp;#160; These are really great tricks that serve as great examples of some of the more powerful things you can do with Silverlight:&lt;/p&gt;  &lt;h4&gt;Links&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/19/cool-silverlight-trick-1.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/19/cool-silverlight-trick-1.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/20/cool-silverlight-trick-2.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/20/cool-silverlight-trick-2.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/22/cool-silverlight-trick-3.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/22/cool-silverlight-trick-3.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/23/cool-silverlight-trick-4.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/23/cool-silverlight-trick-4.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/24/cool-silverlight-trick-5.aspx"&gt;http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/24/cool-silverlight-trick-5.aspx&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;</description><pubDate>Fri, 10 Apr 2009 22:10:10 -0500</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/Jeff-Prosise&amp;rsquo;s-Silverlight-Tips" /></item><item><author>dfb@davidbetz.net</author><title>CitationAttribute for Citing Work</title><description>&lt;p&gt;As a researcher, designer, and open-source developer, it's very important to me to both cite the work I reference as well as to be cited appropriately.&amp;#160; Few things are more lame than finding my research some place on CodePlex disguised work different working under someone else's name... or a file from one of my many open-source systems in someone else's project without my copyright information. &lt;/p&gt;  &lt;p&gt;To help me keep track of where a file or piece of research came from, I wrote a quick attribute to help keep some of this metadata around: CitationAttribute.&amp;#160; This is in my Themelia Framework and I use it extensively in my projects to keep track of where research and files came from.&amp;#160; Below is an example of how to use the attribute.&amp;#160; Fritz Onion was kind enough to allow me to include his ViewState parser in my work.&amp;#160; Notice the metadata in the attribute:&lt;/p&gt;  &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Citation&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;http://www.pluralsight.com/fritz/&amp;quot;&lt;/span&gt;, Copyright = &lt;span style="color: #a31515"&gt;&amp;quot;Copyright (c) 2008 Fritz Onion&amp;quot;&lt;/span&gt;, DateUpdated = &lt;span style="color: #a31515"&gt;&amp;quot;03/25/2008&amp;quot;&lt;/span&gt;)]&#xD;
&lt;span style="color: blue"&gt;public static class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ViewStateXmlBuilder&#xD;
&lt;/span&gt;{&#xD;
    &lt;span style="color: green"&gt;//+ implementation here&#xD;
&lt;/span&gt;}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Here you can see that the reference source is cited as well as the copyright and date the local file was updated with the appropriate version.&amp;#160; Note that this does not replace a file copyright.&amp;#160; I asked Fritz for a complete copyright comment block and he provided that for me.&amp;#160; Above the actual file I include with my Themelia Framework is his actual C# comment stating his actual copyright/disclaimer.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Here's the CitationAttribute as seen in my Themelia Framework:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#region &lt;/span&gt;Copyright&#xD;
&lt;span style="color: green"&gt;//+ Themelia Framework 2.0 - Core Module&#xD;
//+ Copyright © Jampad Technology, Inc. 2007-2009&#xD;
//+&#xD;
//+ This file is a part of the Themelia Framework.&#xD;
//+ The use and distribution terms for this software are covered by the&#xD;
//+ Microsoft Permissive License (Ms-PL) which can be found at&#xD;
//+ http://www.microsoft.com/opensource/licenses.mspx.&#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;#endregion&#xD;
using &lt;/span&gt;System;&#xD;
&lt;span style="color: green"&gt;//+&#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;Themelia&#xD;
{&#xD;
    &lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;&#xD;
    /// &lt;/span&gt;&lt;span style="color: green"&gt;Used to signify that a particular type was pulled from a third part project or piece of research.&#xD;
    &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;&#xD;
    &lt;/span&gt;[&lt;span style="color: #2b91af"&gt;AttributeUsage&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;AttributeTargets&lt;/span&gt;.Class | &lt;span style="color: #2b91af"&gt;AttributeTargets&lt;/span&gt;.Struct | &lt;span style="color: #2b91af"&gt;AttributeTargets&lt;/span&gt;.Interface, Inherited = &lt;span style="color: blue"&gt;false&lt;/span&gt;, AllowMultiple = &lt;span style="color: blue"&gt;false&lt;/span&gt;)]&#xD;
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CitationAttribute &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Attribute&#xD;
    &lt;/span&gt;{&#xD;
        &lt;span style="color: blue"&gt;private readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;_source;&#xD;
&#xD;
        &lt;span style="color: green"&gt;//+&#xD;
        //- @Copyright -//&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;&#xD;
        /// &lt;/span&gt;&lt;span style="color: green"&gt;Represents the copyright of the referenced entity.&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;Copyright { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @DateUpdated -//&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;&#xD;
        /// &lt;/span&gt;&lt;span style="color: green"&gt;Represents the date the local version was updated with the referenced entity.&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;DateUpdated { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @DateUpdated -//&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;&#xD;
        /// &lt;/span&gt;&lt;span style="color: green"&gt;Represents the 2 (i.e. &amp;quot;en&amp;quot;) or 5 (i.e. &amp;quot;en-US&amp;quot;) character culture used to format the date (default = en-US)&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;DateCulture { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @License -//&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;&#xD;
        /// &lt;/span&gt;&lt;span style="color: green"&gt;Represents the license associated with this file (e.g. BSD, MIT, LGPL, Public Domain; default = Custom). This property is not legally binding.  It should only be used as a means of finding the general direction of where to look for the legally binding license.&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;License { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//+&#xD;
        //- @Ctor -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;CitationAttribute(&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;Source)&#xD;
        {&#xD;
            _source = Source;&#xD;
            &lt;span style="color: green"&gt;//+&#xD;
            &lt;/span&gt;DateCulture = &lt;span style="color: #a31515"&gt;&amp;quot;en-US&amp;quot;&lt;/span&gt;;&#xD;
            License = &lt;span style="color: #a31515"&gt;&amp;quot;Custom&amp;quot;&lt;/span&gt;;&#xD;
        }&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;There are a few things to notice about this attribute.&amp;#160; First, there is also a property for DateCulture.&amp;#160; This is very important.&amp;#160; Depending on your culture 05 03 2009 or 03 05 2009 may be March 5th.&amp;#160; Second, there's a License property.&amp;#160; In this example, it's &amp;quot;Custom&amp;quot;.&amp;#160; As another example, if you were to cite Themelia, you would use &amp;quot;Ms-PL&amp;quot; as your License.&amp;#160; Third, the source is required.&amp;#160; It's not that it absolutely has to be a URL, but it's definitely required nonetheless.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Where should you use this file?&amp;#160; Anywhere you cite someone's research, where you use someone's file, or derive from their work.&amp;#160; This doesn't mean only in places where you copy/paste a class from another person's framework.&amp;#160; This also means in places where you find an article online and you use the research in that article to write your own class. &lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;For example, if you were looking online for a solution to create a solution for getting Silverlight to access the clipboard (the mother of all security breaches, but whatever!) and you find a blog post about that, then when you write your classes to use that, you need to cite the blog post.&amp;#160; If you don't, then you are depriving a future developer from seeing the commentary of that code.&amp;#160; By citing the research with the attribute, you are telling the future reader where to see the research.&amp;#160; In the case of using a someone else's files, the attribute will tell future developer's (and you) where to find the updated version.&lt;/p&gt;</description><pubDate>Sat, 04 Apr 2009 03:28:12 -0500</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/CitationAttribute-for-Citing-Work" /></item><item><author>dfb@davidbetz.net</author><category>Silverlight</category><title>Exception Handlers for Silverlight 2.0</title><description>&lt;p&gt;Whereas Themelia is my foundation for all .NET development, it’s a little known fact that I have an internal build of it specifically used for Silverlight.&amp;#160; Among the many features of Themelia for Silverlight (hereafter called “ThemeliaSL”) is something I call Exception Handlers.&amp;#160; This isn’t the same thing as the “catch” block of a try/catch.&amp;#160; No, it’s a concept specific to Silverlight.&amp;#160; Also, this is a fairly discrete feature that you can implement in your own Silverlight applications without the need of my full framework.&amp;#160; However, before you can understand this feature, you need to understand Silverlight currently works with unhandled exceptions.&lt;/p&gt;  &lt;p&gt;When Silverlight throws an exception that’s unhandled, it eventually gets bubbled up to your System.Windows.Application instance.&amp;#160; If you are handling the UnhandledException event of this class, then you have an opportunity to handle this exception on your own.&amp;#160; When your UnhandledException event handler is called, you are passed an instance of System.Windows.ApplicationUnhandledExceptionEventArgs.&amp;#160; In this class you are provided a property named ExceptionObject of type System.Exception which holds the actual exception object that has been thrown.&amp;#160; There’s one other property though: Handled.&amp;#160; This property is a boolean which provides you with the ability to say whether you handled the exception or not.&amp;#160; If you set this property to true, then you are telling Silverlight that the problem has been taken care of.&amp;#160; If you set it to false, then you are telling Silverlight that it’s about to die.&lt;/p&gt;  &lt;p&gt;That’s really all there is to Silverlight exception handling.&amp;#160; You can, however, make things a bit more streamlined.&amp;#160; Say, for example, you know of various types of exceptions that your application or underlying frameworks will throw.&amp;#160; You also know that you want to handle some of them in a specific way.&amp;#160; Or maybe, you just don’t want any communications exceptions to ever be sent back to the client.&amp;#160; For situations like these, you can use the concept I refer to as exception handlers.&lt;/p&gt;  &lt;p&gt;Before we implement this concept, lets see how it will be used first:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Application &lt;/span&gt;: Themelia.Windows.&lt;span style="color: #2b91af"&gt;Application&#xD;
&lt;/span&gt;{&#xD;
    &lt;span style="color: blue"&gt;public &lt;/span&gt;Application()&#xD;
        : &lt;span style="color: blue"&gt;base&lt;/span&gt;()&#xD;
    {&#xD;
        AddExceptionHandler(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;CommunicationException&lt;/span&gt;), &lt;span style="color: blue"&gt;delegate&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;ex)&#xD;
        {&#xD;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(ex.InnerException == &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
            {&#xD;
&#xD;
                ReportExceptionToFirebug(ex.InnerException);&#xD;
                &lt;span style="color: blue"&gt;return true&lt;/span&gt;;&#xD;
            }&#xD;
            &lt;span style="color: green"&gt;//+ &#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return false&lt;/span&gt;;&#xD;
        });&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;Essentially, call the base constructor of the Application class we are about to create.&amp;#160; Then, for each exception that you want to handle, register it with the AddExceptionHandler method, sending it the type of the exception and a delegate of type Func&amp;lt;Exception, Boolean&amp;gt;.&amp;#160; In this example, when an unhandled exception of type CommunicationException is thrown, we automatically check to see if it has an inner exception.&amp;#160; If so, we report the exception in a special way and mark the exception as handled.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;You could also add more exception handlers.&amp;#160; Here’s another example:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;AddExceptionHandler(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ArgumentException&lt;/span&gt;), &lt;span style="color: blue"&gt;delegate&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;ex)&#xD;
{&#xD;
    ReportValidationError(ex);&#xD;
    &lt;span style="color: blue"&gt;return true&lt;/span&gt;;&#xD;
});&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;While this example is a rather silly one (because validation shouldn’t throw exceptions!), it does go to show you this is essentially a declarative model for exception handling.&amp;#160; Now it’s time to move on to build the thing.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;First, create your own abstract version of System.Windows.Application.&amp;#160; This is typically a good idea anyways.&amp;#160; It allows you to control your applications in a very streamlined manner.&amp;#160; In this class, add the following static member:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Type&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;Boolean&lt;/span&gt;&amp;gt;&amp;gt; HandlerRegistry = &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: #2b91af"&gt;Type&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;Boolean&lt;/span&gt;&amp;gt;&amp;gt;();&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;This represents a registry of all exceptions handlers registered to your application.&amp;#160; It’s a dictionary with the key representing the Type of the exception and the value representing a delegate to be called when that exception is raised.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;You’ll also need a standard .NET locking object:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Object &lt;/span&gt;_lock = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Object&lt;/span&gt;(); &lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;Now add the following method:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//- #AddExceptionHandler -// &#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;protected void &lt;/span&gt;AddExceptionHandler(&lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;type, &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;Boolean&lt;/span&gt;&amp;gt; handler)&#xD;
{&#xD;
    &lt;span style="color: blue"&gt;lock &lt;/span&gt;(_lock)&#xD;
    {&#xD;
        HandlerRegistry.Add(type, handler);&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;This will allow you to register exception handlers from your concrete instance of your custom application class.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Now it’s on to the meat of the implementation.&amp;#160; In your base class application class constructor, handle the UnhandledException event.&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.UnhandledException += &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EventHandler&lt;/span&gt;&amp;lt;System.Windows.&lt;span style="color: #2b91af"&gt;ApplicationUnhandledExceptionEventArgs&lt;/span&gt;&amp;gt;(OnUnhandledException);&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;Then, in the method that will be called upon the event being raised, do something like this:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//- #OnUnhandledException -// &#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;protected virtual void &lt;/span&gt;OnUnhandledException(&lt;span style="color: #2b91af"&gt;Object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;ApplicationUnhandledExceptionEventArgs &lt;/span&gt;ea)&#xD;
{&#xD;
    &lt;span style="color: blue"&gt;lock &lt;/span&gt;(_lock)&#xD;
    {&#xD;
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(HandlerRegistry.Count &amp;gt; 0)&#xD;
        {&#xD;
            &lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;exception = ea.ExceptionObject;&#xD;
            &lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;type = exception.GetType();&#xD;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(HandlerRegistry.ContainsKey(type))&#xD;
            {&#xD;
                ea.Handled = HandlerRegistry[type](exception);&#xD;
            }&#xD;
        }&#xD;
    }&#xD;
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(!System.Diagnostics.&lt;span style="color: #2b91af"&gt;Debugger&lt;/span&gt;.IsAttached &amp;amp;&amp;amp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.AutoReportErrorToDOM &amp;amp;&amp;amp; !ea.Handled)&#xD;
    {&#xD;
        ea.Handled = &lt;span style="color: blue"&gt;true&lt;/span&gt;;&#xD;
        &lt;span style="color: #2b91af"&gt;Deployment&lt;/span&gt;.Current.Dispatcher.BeginInvoke(&lt;span style="color: blue"&gt;delegate &lt;/span&gt;{ ReportErrorToDOM(ea); });&#xD;
    }&#xD;
} &lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;Essentially, if there are any registered handlers, check to see if the currently thrown exception is one of those exception registered to be handled.&amp;#160; If so, then pull the delegate from the registry and call it.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Notice that the delegate that we registered is Func&amp;lt;Exception, Boolean&amp;gt;.&amp;#160; Functionally, this means is that the delegate will accept an Exception object and return a boolean.&amp;#160; Interpreted, this means that in the delegate you register you need to return a boolean representing whether you want the exception handled or not.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;You may also notice in the above code that there is a property named AutoReportErrorToDOM.&amp;#160; This does exactly what it says&amp;#160; and it’s nothing too exciting:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//- @AutoReportErrorToDOM -// &#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Boolean &lt;/span&gt;AutoReportErrorToDOM { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;The ReportErrorToDOM method is the same one that Visual Studio 2008 throws in with the Silverlight template.&amp;#160; For completeness, here it is:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//- #ReportErrorToDOM -// &#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;protected void &lt;/span&gt;ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs ea)&#xD;
{&#xD;
    &lt;span style="color: blue"&gt;try&#xD;
    &lt;/span&gt;{&#xD;
        &lt;span style="color: #2b91af"&gt;String &lt;/span&gt;errorMsg = ea.ExceptionObject.Message + ea.ExceptionObject.StackTrace;&#xD;
        errorMsg = errorMsg.Replace(&lt;span style="color: #a31515"&gt;'&amp;quot;'&lt;/span&gt;, &lt;span style="color: #a31515"&gt;'\''&lt;/span&gt;).Replace(&lt;span style="color: #a31515"&gt;&amp;quot;\r\n&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;@&amp;quot;\n&amp;quot;&lt;/span&gt;);&#xD;
        System.Windows.Browser.&lt;span style="color: #2b91af"&gt;HtmlPage&lt;/span&gt;.Window.Eval(&lt;span style="color: #a31515"&gt;&amp;quot;throw new Error(\&amp;quot;Unhandled Error in Silverlight 2 Application &amp;quot; &lt;/span&gt;+ errorMsg + &lt;span style="color: #a31515"&gt;&amp;quot;\&amp;quot;);&amp;quot;&lt;/span&gt;);&#xD;
    }&#xD;
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;)&#xD;
    {&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;At this point, you have everything you need to make the samples that we went through work properly.&amp;#160; Just be sure to base your application class on the new one and you’ll be set.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;One important note is that when you are using custom visual entities in Silverlight, you need to make sure that you properly register the namespace in XAML.&amp;#160; For example, say the above class was called “Application” in the “Themelia.Windows” CLR namespace in the “Themelia.Silverlight” assembly.&amp;#160; For this configuration, you would use the following xaml:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;t&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Application &#xD;
    &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot; &#xD;
    &lt;/span&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;x&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot; &#xD;
    &lt;/span&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;t&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:Themelia.Windows;assembly=Themelia.Silverlight&amp;quot; &#xD;
    &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;Class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Sample.Application&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;With this, you’re all set.&lt;/p&gt;</description><pubDate>Tue, 31 Mar 2009 23:27:31 -0500</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/Exception-Handlers-for-Silverlight-20" /></item><item><author>dfb@davidbetz.net</author><category>Silverlight</category><title>Tip: Quick Reflector Loading for .NET and Silverlight</title><description>&lt;p&gt;In my daily development there are three tools that I keep open almost constantly:&amp;#160; Visual Studio 2008, Windows Debugger, and Reflector.&amp;#160; The first is obvious, the second is for extreme-debugging, and the third so I can have a clue what I’m working with (...I have NO idea how people do .NET or Silverlight development without reflector!)&amp;#160; The first two I access with icons, while the third is one that I open and close at least 10 times a day.&lt;/p&gt;  &lt;p&gt;To quickly access reflector (as well as Notepad2 and a whole host of sysinternals apps!) I throw it in my Windows folder so I can access it from the Run box.&amp;#160; Not only that, but I typically rename tools I throw in there to have only one letter.&amp;#160; Reflector is “r”.&amp;#160; So, I hit Win-R and type “r”.&amp;#160; Up comes reflector.&amp;#160; Here’s the thing though: I work in both .NET and Silverlight equally.&amp;#160; Yet, Reflector only loads ONE of them.&amp;#160; What to do?&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The fix is simple: copy r.exe to rs.exe.&lt;/strong&gt;&amp;#160; When I load r.exe, I select .NET.&amp;#160; When I load rs.exe, I select Silverlight.&amp;#160; Now I when I hit Win-R, I can type either “r” or “rs” depending on what framework I want to inspect.&amp;#160; You could even take the concept further by making a “rf.exe” for the compact framework”&amp;#160; Each “x.exe” will have it’s own “x.cfg” so the configurations won’t bleed over each other.&lt;/p&gt;</description><pubDate>Wed, 18 Mar 2009 22:23:08 -0500</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/Tip-Quick-Reflector-Loading-for-NET-and-Silverlight" /></item><item><author>dfb@davidbetz.net</author><title>Thanks for the feedback ! (Re: Understanding WCF Services in Silverlight 2)</title><description>&lt;p&gt;A few months back I published a document on my web site entitled &amp;quot;Understanding WCF Services in Silverlight 2&amp;quot;.&amp;#160; I wrote this document so people could have a solid understand of how to use WCF as well as some of the core WCF best practices.&amp;#160; The document explains everything from data contracts to service contracts, from asynchronous communication to SSL security, and from fault management to JSON communication.&amp;#160; It did this for both .NET as well as Silverlight. &lt;/p&gt;  &lt;p&gt;Well, goodness, it's definitely met my expectations.&amp;#160; It's quickly become the absolute top most traffic mover on my web site.&amp;#160; It even flew by my &lt;a href="http://www.davidbetz.net/graphics/"&gt;JavaScript Graphics Development&lt;/a&gt; publication, which was a traffic mover very hard to beat.&amp;#160; The document also ended up on the Microsoft WCF homepage for three months and... a Senior Program Manager of the Connected Systems division even asked me to speak at the Mix conference on the topic of the document (of course I turned him down... it's just so much easier NOT to speak at a conference.)&lt;/p&gt;  &lt;p&gt;So, thanks to everyone to came to the web site to read the document online or to download the PDF or XPS version of it.&amp;#160; Thanks also to everyone who left positive feedback on the web site.&amp;#160; Apparently, the document really has helped a lot of people in their pursuit to understand WCF better.&amp;#160; As I expected (well, as I knew!), people are sick and tired of the same old boring drag-n-drop videos and template-based file creation nonsense which prohibits the actual learning of the technology.&lt;/p&gt;  &lt;p&gt;Given the absolutely astounding lack of respect and gratitude I get in person, the comments from the web site have gone a long way in helping convince me that I should continue my research and publication of this type of material.&amp;#160; It's my hope that people continue to find benefit in my research and continue to take the time to drop me a line telling me it was helpful.&lt;/p&gt;</description><pubDate>Sat, 07 Mar 2009 14:21:07 -0600</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/Thanks-for-the-feedback--Re-Understanding-WCF-Services-in-Silverlight-2" /></item><item><author>dfb@davidbetz.net</author><category>Silverlight</category><title>Adding XmlNode to Silverlight</title><description>&lt;p&gt;Of the many types of data I work with, XML shows up all the time.&amp;#160; However, when working in Silverlight, your XML options are dramatically limited.&amp;#160; For example, for some reason Microsoft totally forgot to add a simple XmlNode class.&amp;#160; Microsoft seems to think that using LINQ for XML will solve all our XML problems.&amp;#160; Well, most of the stuff that I do on a daily basis has nothing to do with extensive querying XML.&amp;#160; I just need something simple to pull quick data.&amp;#160; Not only that, but LINQ for XML is in the System.Xml.Linq assembly, which is not a native Silverlight assembly.&amp;#160; I’m not going to bloat my XAP file for a single dependency.&lt;/p&gt;  &lt;p&gt;So, in my internal build of Themelia for Silverlight, you will find the Themelia.Xml.XmlNode class.&amp;#160; I use this all over the build entire XML trees and to search the same tree for elements I need.&amp;#160; All this in one small discrete class that doesn’t require you to bloat your XAP file.&amp;#160; Here’s a sample of how to use my XmlNode class:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;XmlReader &lt;/span&gt;reader = &lt;span style="color: #2b91af"&gt;XmlReader&lt;/span&gt;.Create(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringReader&lt;/span&gt;(&lt;span style="color: #a31515"&gt;@&amp;quot;&amp;lt;s:Envelope xmlns:s=&amp;quot;&amp;quot;http://schemas.xmlsoap.org/soap/envelope/&amp;quot;&amp;quot;&amp;gt;&#xD;
    &amp;lt;s:Body&amp;gt;&#xD;
    &amp;lt;s:Fault&amp;gt;&#xD;
      &amp;lt;faultcode&amp;gt;s:Client&amp;lt;/faultcode&amp;gt;&#xD;
      &amp;lt;faultstring xml:lang=&amp;quot;&amp;quot;en-US&amp;quot;&amp;quot;&amp;gt;This is the fault reason.&amp;lt;/faultstring&amp;gt;&#xD;
      &amp;lt;detail&amp;gt;&#xD;
        &amp;lt;FaultDetail xmlns=&amp;quot;&amp;quot;http://schemas.datacontract.org/2004/07/Sample.Service&amp;quot;&amp;quot; xmlns:i=&amp;quot;&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;&amp;quot;&amp;gt;&#xD;
          &amp;lt;Reason&amp;gt;This is the fault reason.&amp;lt;/Reason&amp;gt;&#xD;
          &amp;lt;Source&amp;gt;GetPersonData&amp;lt;/Source&amp;gt;&#xD;
        &amp;lt;/FaultDetail&amp;gt;&#xD;
      &amp;lt;/detail&amp;gt;&#xD;
    &amp;lt;/s:Fault&amp;gt;&#xD;
    &amp;lt;/s:Body&amp;gt;&#xD;
    &amp;lt;/s:Envelope&amp;gt;&amp;quot;&lt;/span&gt;));&#xD;
&lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;node = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlNode&lt;/span&gt;(reader);&#xD;
&lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;faultDetailNode = node.FindDescendant(&lt;span style="color: #a31515"&gt;&amp;quot;faultDetail&amp;quot;&lt;/span&gt;);&#xD;
stackpanel01.Children.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TextBlock&#xD;
&lt;/span&gt;{&#xD;
    Text = faultDetailNode.FirstChild.TextContent&#xD;
});&#xD;
stackpanel01.Children.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TextBlock&#xD;
&lt;/span&gt;{&#xD;
    Text = faultDetailNode.AttributeDictionary[&lt;span style="color: #a31515"&gt;&amp;quot;xmlns&amp;quot;&lt;/span&gt;]&#xD;
});&#xD;
stackpanel01.Children.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TextBlock&#xD;
&lt;/span&gt;{&#xD;
    Text = faultDetailNode.AttributeDictionary[&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:i&amp;quot;&lt;/span&gt;]&#xD;
});&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;It does a few more things that you can see by looking at the source for it, but this is essentially all I need in for XML processing on most days.&amp;#160; Here’s the source for XmlNode.cs:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System;&#xD;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Collections.Generic;&#xD;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.IO;&#xD;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Linq;&#xD;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Xml;&#xD;
&lt;span style="color: green"&gt;//+&#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;Themelia.Xml&#xD;
{&#xD;
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlNode&#xD;
    &lt;/span&gt;{&#xD;
        &lt;span style="color: green"&gt;//- @Name -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;Name { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @TextContent -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;TextContent { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @Children -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;XmlNode&lt;/span&gt;&amp;gt; NodeList { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @AttributeMap -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt; AttributeDictionary { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @FirstChild -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;FirstChild&#xD;
        {&#xD;
            &lt;span style="color: blue"&gt;get&#xD;
            &lt;/span&gt;{&#xD;
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(NodeList.Count &amp;gt; 0)&#xD;
                {&#xD;
                    &lt;span style="color: blue"&gt;return &lt;/span&gt;NodeList[0];&#xD;
                }&#xD;
                &lt;span style="color: green"&gt;//+&#xD;
                &lt;/span&gt;&lt;span style="color: blue"&gt;return null&lt;/span&gt;;&#xD;
            }&#xD;
        }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//+&#xD;
        //- @Ctor -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;XmlNode()&#xD;
        {&#xD;
            NodeList = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;XmlNode&lt;/span&gt;&amp;gt;();&#xD;
            AttributeDictionary = &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: #2b91af"&gt;String&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt;();&#xD;
        }&#xD;
        &lt;span style="color: blue"&gt;public &lt;/span&gt;XmlNode(&lt;span style="color: #2b91af"&gt;XmlReader &lt;/span&gt;xmlReader)&#xD;
            : &lt;span style="color: blue"&gt;this&lt;/span&gt;()&#xD;
        {&#xD;
            Initialize(xmlReader);&#xD;
        }&#xD;
        &lt;span style="color: blue"&gt;public &lt;/span&gt;XmlNode(&lt;span style="color: #2b91af"&gt;Stream &lt;/span&gt;xmlStream)&#xD;
            : &lt;span style="color: blue"&gt;this&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;XmlReader&lt;/span&gt;.Create(xmlStream))&#xD;
        {&#xD;
        }&#xD;
        &lt;span style="color: blue"&gt;public &lt;/span&gt;XmlNode(&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;name)&#xD;
            : &lt;span style="color: blue"&gt;this&lt;/span&gt;()&#xD;
        {&#xD;
            Name = name;&#xD;
        }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- $Initialize -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;Initialize(&lt;span style="color: #2b91af"&gt;XmlReader &lt;/span&gt;reader)&#xD;
        {&#xD;
            reader.Read();&#xD;
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.Name = reader.Name;&#xD;
            &lt;span style="color: green"&gt;//+ attribute&#xD;
            &lt;/span&gt;reader.MoveToElement();&#xD;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(reader.HasAttributes)&#xD;
            {&#xD;
                reader.MoveToFirstAttribute();&#xD;
                AttributeDictionary.Add(reader.Name, reader.Value);&#xD;
                &lt;span style="color: blue"&gt;while &lt;/span&gt;(reader.MoveToNextAttribute())&#xD;
                {&#xD;
                    AttributeDictionary.Add(reader.Name, reader.Value);&#xD;
                }&#xD;
            }&#xD;
            &lt;span style="color: green"&gt;//+ node&#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;while &lt;/span&gt;(reader.Read())&#xD;
            {&#xD;
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(reader.NodeType == &lt;span style="color: #2b91af"&gt;XmlNodeType&lt;/span&gt;.Element)&#xD;
                {&#xD;
                    NodeList.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlNode&lt;/span&gt;(reader.ReadSubtree()));&#xD;
                }&#xD;
                &lt;span style="color: blue"&gt;else if &lt;/span&gt;(reader.NodeType == &lt;span style="color: #2b91af"&gt;XmlNodeType&lt;/span&gt;.Text)&#xD;
                {&#xD;
                    TextContent = reader.ReadContentAsString();&#xD;
                }&#xD;
            }&#xD;
        }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @FindDescendant -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;FindDescendant(&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;name)&#xD;
        {&#xD;
            &lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;foundNode = NodeList.FirstOrDefault(p =&amp;gt; p.Name.Equals(name, &lt;span style="color: #2b91af"&gt;StringComparison&lt;/span&gt;.InvariantCultureIgnoreCase));&#xD;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(foundNode != &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
            {&#xD;
                &lt;span style="color: blue"&gt;return &lt;/span&gt;foundNode;&#xD;
            }&#xD;
            &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;node &lt;span style="color: blue"&gt;in &lt;/span&gt;NodeList)&#xD;
            {&#xD;
                foundNode = node.FindDescendant(name);&#xD;
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(foundNode != &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
                {&#xD;
                    &lt;span style="color: blue"&gt;return &lt;/span&gt;foundNode;&#xD;
                }&#xD;
            }&#xD;
            &lt;span style="color: green"&gt;//+&#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;foundNode;&#xD;
        }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @FindDescendantList -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;XmlNode&lt;/span&gt;&amp;gt; FindDescendantList(&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;name)&#xD;
        {&#xD;
            &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;XmlNode&lt;/span&gt;&amp;gt; nodeList = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;XmlNode&lt;/span&gt;&amp;gt;();&#xD;
            &lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;foundNode = NodeList.FirstOrDefault(p =&amp;gt; p.Name.Equals(name, &lt;span style="color: #2b91af"&gt;StringComparison&lt;/span&gt;.InvariantCultureIgnoreCase));&#xD;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(foundNode != &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
            {&#xD;
                nodeList.Add(foundNode);&#xD;
                foundNode = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&#xD;
            }&#xD;
            &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;node &lt;span style="color: blue"&gt;in &lt;/span&gt;NodeList)&#xD;
            {&#xD;
                foundNode = node.FindDescendant(name);&#xD;
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(foundNode != &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
                {&#xD;
                    nodeList.Add(foundNode);&#xD;
                    foundNode = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&#xD;
                }&#xD;
            }&#xD;
            &lt;span style="color: green"&gt;//+&#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;nodeList;&#xD;
        }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @GetChildDictionary -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt; GetChildDictionary()&#xD;
        {&#xD;
            &lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt; map = &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: #2b91af"&gt;String&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt;();&#xD;
            &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;node &lt;span style="color: blue"&gt;in &lt;/span&gt;NodeList)&#xD;
            {&#xD;
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.IsNullOrEmpty(node.TextContent))&#xD;
                {&#xD;
                    map.Add(node.Name, node.TextContent);&#xD;
                }&#xD;
            }&#xD;
            &lt;span style="color: green"&gt;//+&#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;map;&#xD;
        }&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;Yeah, there’s more it could probably do and I’ll probably add more to it in the future, but this little class has worked in all my XML scenarios so far.&lt;/p&gt;</description><pubDate>Tue, 17 Feb 2009 21:42:55 -0600</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/Adding-XmlNode-to-Silverlight" /></item><item><author>dfb@davidbetz.net</author><category>Silverlight</category><title>Obtaining Enumeration Names and Values in Silverlight 2.0</title><description>&lt;p&gt;In .NET, when you are dealing with singular enumerations (the ones singular names) or flags enumerations (the ones with plural names), you have the ability to access the names and values of each of the items in the enumeration.&amp;#160; For example, the below code iterates through and prints out both the values and names of the enumeration items:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System;&#xD;
&lt;span style="color: green"&gt;//+&#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;Sample&#xD;
{&#xD;
    &lt;span style="color: blue"&gt;public enum &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Component&#xD;
    &lt;/span&gt;{&#xD;
        Keyboard,&#xD;
        Mouse,&#xD;
        Display,&#xD;
        Disk,&#xD;
        Memory,&#xD;
        Network&#xD;
    }&#xD;
&#xD;
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Program&#xD;
    &lt;/span&gt;{&#xD;
        &lt;span style="color: green"&gt;//- $Main -//&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;private static void &lt;/span&gt;Main(&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;[] args)&#xD;
        {&#xD;
            &lt;span style="color: green"&gt;//+ name&#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;name &lt;span style="color: blue"&gt;in &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Enum&lt;/span&gt;.GetNames(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Component&lt;/span&gt;)))&#xD;
            {&#xD;
                &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(name);&#xD;
            }&#xD;
            &lt;span style="color: green"&gt;//+ value&#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Object &lt;/span&gt;value &lt;span style="color: blue"&gt;in &lt;/span&gt;&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;Component&lt;/span&gt;)))&#xD;
            {&#xD;
                &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine((&lt;span style="color: #2b91af"&gt;Int32&lt;/span&gt;)value);&#xD;
            }&#xD;
        }&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;Now let’s go to do the same thing in Silverlight 2.0.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;&lt;a href="http://www.netfxharmonics.com/imagestore/3d90d6ce-76b2-4ffd-ae41-4f226e3a4742"&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://www.netfxharmonics.com/imagestore/d4215acf-b62c-458e-979d-0be14c4dabd3" width="215" height="228" /&gt;&lt;/a&gt; &lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Err... wait a minute.&amp;#160; Where’s GetNames and GetValues?&amp;#160; Well, they don’t exist.&amp;#160; Fortunately, we have the ability to access these via reflection.&amp;#160; To obtain the names, we just need to obtain the Type object of our enumeration and call GetFields with the Public and Static binding flags set, and look in the resulting FieldInfo array.&amp;#160; Each FieldInfo object will have a Name property without item name.&amp;#160; For the values, we simply use Enum.Parse to turn that name into the actual value.&amp;#160; For the underlying value, we can just cast that to the underlying type of the enumeration.&amp;#160; In the example above, that would be System.Int32.&amp;#160; Here’s all that in action:&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;&amp;#160;&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//- $OnLoaded -//&#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;OnLoaded(&lt;span style="color: #2b91af"&gt;Object &lt;/span&gt;sender, System.Windows.&lt;span style="color: #2b91af"&gt;RoutedEventArgs &lt;/span&gt;e)&#xD;
{&#xD;
    &lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;enumType = &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Component&lt;/span&gt;);&#xD;
    System.Reflection.&lt;span style="color: #2b91af"&gt;FieldInfo&lt;/span&gt;[] fiArray = enumType.GetFields(System.Reflection.&lt;span style="color: #2b91af"&gt;BindingFlags&lt;/span&gt;.Public | System.Reflection.&lt;span style="color: #2b91af"&gt;BindingFlags&lt;/span&gt;.Static);&#xD;
    &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(System.Reflection.&lt;span style="color: #2b91af"&gt;FieldInfo &lt;/span&gt;fi &lt;span style="color: blue"&gt;in &lt;/span&gt;fiArray)&#xD;
    {&#xD;
        &lt;span style="color: green"&gt;//+ name&#xD;
        &lt;/span&gt;sp01.Children.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TextBlock&#xD;
        &lt;/span&gt;{&#xD;
             Text = fi.Name&#xD;
        });&#xD;
    }&#xD;
    &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(System.Reflection.&lt;span style="color: #2b91af"&gt;FieldInfo &lt;/span&gt;fi &lt;span style="color: blue"&gt;in &lt;/span&gt;fiArray)&#xD;
    {&#xD;
        &lt;span style="color: green"&gt;//+ value&#xD;
        &lt;/span&gt;sp01.Children.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TextBlock&#xD;
        &lt;/span&gt;{&#xD;
            Text = ((&lt;span style="color: #2b91af"&gt;Int32&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;Enum&lt;/span&gt;.Parse(enumType, fi.Name, &lt;span style="color: blue"&gt;false&lt;/span&gt;)).ToString()&#xD;
        });&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;I’ve left the namespaces of the items in the System.Reflection namespace in place so you can see exactly what types were working with here.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Of course, you can always wrap this up into it’s own class so you can reuse this logic all over:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;Themelia&#xD;
{&#xD;
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EnumReader&#xD;
    &lt;/span&gt;{&#xD;
        &lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;&#xD;
        /// &lt;/span&gt;&lt;span style="color: green"&gt;Gets the names of an enumeration type.&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;&#xD;
        /// &amp;lt;param name=&amp;quot;enumerationType&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;Type of enumeration.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;&#xD;
        /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;List of names of the enumeration.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt; GetNameList(&lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;enumType)&#xD;
        {&#xD;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(!enumType.IsEnum)&#xD;
            {&#xD;
                &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Specified generic parameter must be an enumeration.&amp;quot;&lt;/span&gt;);&#xD;
            }&#xD;
            &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt; nameList = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt;();&#xD;
            &lt;span style="color: green"&gt;//+ type&#xD;
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FieldInfo&lt;/span&gt;[] fiArray = enumType.GetFields(&lt;span style="color: #2b91af"&gt;BindingFlags&lt;/span&gt;.Public | &lt;span style="color: #2b91af"&gt;BindingFlags&lt;/span&gt;.Static);&#xD;
            &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;FieldInfo &lt;/span&gt;fi &lt;span style="color: blue"&gt;in &lt;/span&gt;fiArray)&#xD;
            {&#xD;
                nameList.Add(fi.Name);&#xD;
            }&#xD;
            &lt;span style="color: green"&gt;//+&#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;nameList;&#xD;
        }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @GetNameList -//&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;&#xD;
        /// &lt;/span&gt;&lt;span style="color: green"&gt;Gets the names of an enumeration type.&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;&#xD;
        /// &amp;lt;typeparam name=&amp;quot;T&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;Type of enumeration.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/typeparam&amp;gt;&#xD;
        /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;List of names of the enumeration.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&amp;gt; GetNameList&amp;lt;T&amp;gt;() &lt;span style="color: blue"&gt;where &lt;/span&gt;T : &lt;span style="color: blue"&gt;struct&#xD;
        &lt;/span&gt;{&#xD;
            &lt;span style="color: blue"&gt;return &lt;/span&gt;GetNameList(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(T));&#xD;
        }&#xD;
&#xD;
        &lt;span style="color: green"&gt;//- @GetValueList -//&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;&#xD;
        /// &lt;/span&gt;&lt;span style="color: green"&gt;Gets the values of an enumeration type.&#xD;
        &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;&#xD;
        /// &amp;lt;typeparam name=&amp;quot;T&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;Type of enumeration.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/typeparam&amp;gt;&#xD;
        /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;List of values of the enumeration.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;&#xD;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;T&amp;gt; GetValueList&amp;lt;T&amp;gt;() &lt;span style="color: blue"&gt;where &lt;/span&gt;T : &lt;span style="color: blue"&gt;struct&#xD;
        &lt;/span&gt;{&#xD;
            &lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;enumType = &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(T);&#xD;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(!enumType.IsEnum)&#xD;
            {&#xD;
                &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Specified generic parameter must be an enumeration.&amp;quot;&lt;/span&gt;);&#xD;
            }&#xD;
            &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;T&amp;gt; valueList = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;T&amp;gt;();&#xD;
            &lt;span style="color: #2b91af"&gt;FieldInfo&lt;/span&gt;[] fiArray = enumType.GetFields(&lt;span style="color: #2b91af"&gt;BindingFlags&lt;/span&gt;.Public | &lt;span style="color: #2b91af"&gt;BindingFlags&lt;/span&gt;.Static);&#xD;
            &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;FieldInfo &lt;/span&gt;fi &lt;span style="color: blue"&gt;in &lt;/span&gt;fiArray)&#xD;
            {&#xD;
                valueList.Add((T)&lt;span style="color: #2b91af"&gt;Enum&lt;/span&gt;.Parse(enumType, fi.Name, &lt;span style="color: blue"&gt;false&lt;/span&gt;));&#xD;
            }&#xD;
            &lt;span style="color: green"&gt;//+&#xD;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;valueList;&#xD;
        }&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;In this example class, you can see that two of the methods are actually declared as generic.&amp;#160; So, to use them like this:&lt;/p&gt;&#xD;
&#xD;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//- $OnLoaded -//&#xD;
&lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;OnLoaded(&lt;span style="color: #2b91af"&gt;Object &lt;/span&gt;sender, System.Windows.&lt;span style="color: #2b91af"&gt;RoutedEventArgs &lt;/span&gt;e)&#xD;
{&#xD;
    &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;String &lt;/span&gt;name &lt;span style="color: blue"&gt;in &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EnumReader&lt;/span&gt;.GetNameList&amp;lt;&lt;span style="color: #2b91af"&gt;Component&lt;/span&gt;&amp;gt;())&#xD;
    {&#xD;
        &lt;span style="color: green"&gt;//+ name&#xD;
        &lt;/span&gt;sp01.Children.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TextBlock&#xD;
        &lt;/span&gt;{&#xD;
            Text = name&#xD;
        });&#xD;
    }&#xD;
    &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Component &lt;/span&gt;component &lt;span style="color: blue"&gt;in &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EnumReader&lt;/span&gt;.GetValueList&amp;lt;&lt;span style="color: #2b91af"&gt;Component&lt;/span&gt;&amp;gt;())&#xD;
    {&#xD;
        &lt;span style="color: green"&gt;//+ value&#xD;
        &lt;/span&gt;sp01.Children.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TextBlock&#xD;
        &lt;/span&gt;{&#xD;
            Text = ((&lt;span style="color: #2b91af"&gt;Int32&lt;/span&gt;)component).ToString()&#xD;
        });&#xD;
    }&#xD;
}&lt;/pre&gt;&#xD;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&#xD;
&#xD;
&lt;p&gt;One thing to keep in mind is that reflection does have a performance hit.&amp;#160; However, given that most of WPF, Silverlight, and WCF are all about constant reflection, you can rest comfortably that it’s not nearly as bad as some people would say.&amp;#160; Having said that, if your application profiling does say that you are reflecting too much, you can always cache the data returned from these method and access the cache instead.&amp;#160; Don’t however, cache for the sake of caching.&amp;#160; Saying “We’re always going to cache, just to be consistent” is as stupid as saying “We’re always going to drive 45mph, just to be consistent.”&amp;#160; This kills people on both the interstate and in school zones.&amp;#160; Make your caching decisions (and ALL other decisions!) based upon your current situation never upon dangerous mindless consistency.&lt;/p&gt;</description><pubDate>Thu, 12 Feb 2009 22:16:04 -0600</pubDate><a10:link href="http://www.netfxharmonics.com/2009/04/Obtaining-Enumeration-Names-and-Values-in-Silverlight-20" /></item><item><author>dfb@davidbetz.net</author><category>Silverlight</category><title>Silverlight Feature Requests</title><description>&lt;p&gt;Silverlight is probably the most important technology to be released since Firefox 1.0 and that since .NET 1.0.&amp;#160; However, as with most early-edition pieces of software, there are some major things missing.&amp;#160; Below is a list of things that I request that Microsoft add with a quick note on each.&amp;#160; It ranges from a few UI things to the more hardcore mechanical things (...things that many developers will say are meaningless until they learn how to spell C-L-R).&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;GIF Support&lt;/strong&gt; - Obvious.&amp;#160; It's very odd that some manager somewhere said &amp;quot;no one ever uses GIF anymore&amp;quot;.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Style Inheritance&lt;/strong&gt; - Another obvious one.&amp;#160; We who knew WPF long before Silverlight was around THRIVE on this. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DockPanel&lt;/strong&gt; - COME ON! You MUST be joking! I shouldn't have to use a third party CodePlex control for this. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;VisualBrush&lt;/strong&gt; - The ability to paint controls on a background and in other places will go a long way in helping people creating more interactive help files and training software.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;RelativeSource&lt;/strong&gt; - The ability to bind one element's property to another is EXTREMELY important (i.e. my height == my parent's height).&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;MultiView&lt;/strong&gt; - It takes almost no code to write this; just make it native so we don't have dozens of versions all over. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;WebHttpBinding for JSON&lt;/strong&gt; - POX is less important, but would be nice; JSON is the de facto web standard. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;System.Security.Cryptography.RSA with providers &lt;/strong&gt;- This would greatly increase the security of client-server communication. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Workflow Foundation&lt;/strong&gt; - Even a light version with only the basic activities (for, if, while, etc...) would be nice. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;SVG Viewer&lt;/strong&gt; - This should shut up the anti-Microsoft cult. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Better font rendering&lt;/strong&gt; - It's HORRIBLE in 2.0. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;iPhone Support&lt;/strong&gt; - I think this may take a miracle. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;MultiTouch&lt;/strong&gt; - Need this for iPhone support. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;CSS3 DOM Selector (&lt;/strong&gt;&lt;a href="http://www.w3.org/TR/selectors-api/"&gt;http://www.w3.org/TR/selectors-api/&lt;/a&gt;&lt;strong&gt;)&lt;/strong&gt; - So we use it instead of jQuery's version for closer-to-native speed on EVERY browser without even needing JQuery. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;A XMLHttpRequest object&lt;/strong&gt; - This would allow us to use Silverlight's CrossDomainPolicy.xml stuff for cross domain stuff instead of playing games with browser detection nonsense and adding hacks for browsers which don't support it. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;API for browser abstraction&lt;/strong&gt; - Web developers HATE having to do lame detection to figure out if we are on IE so we can talk to it like a child.&amp;#160; Give us the ability to create managed extensions to Silverlight so we can add in our pain-in-the-butt browser differences in Silverlight instead of relying on painfully slow JScript rendering and browser detection. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Service for extensions&lt;/strong&gt; - This goes with the last one.&amp;#160; We should have the ability to 1) extend the hardcore functionality of Silverlight and 2) have a centralize service that Silverlight calls to download our functionality when our application requests it.&amp;#160; This would be very just like what Firefox does when it needs a plugin.&amp;#160; It would also do auto-updating like with Firefox extensions. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;JSON deserializer that actually works to deserialize data serialized by the JSON serializer&lt;/strong&gt; - JSON is critically important to the web; it should be supported better. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;The ability to get 500 HTTP status codes from Firefox, Chrome, and IE&lt;/strong&gt; - This would allow us to use fault contracts in WCF.&amp;#160; This would have to be a pain to implement, though. So, I wouldn't expect it for a while. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;The ability for NPCTRL to communicate CLR configuration information to the CoreCLR to tweak GC things that are normally in configuration&lt;/strong&gt; - If the hosting NPCTRL control would just allow us to give it configuration parameters to send to the CoreCLR, that would RULE (like we can already do in .NET with configuration). &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Hosting documentation that doesn't SUCK&lt;/strong&gt; - Using Win32/ATL to host a Silverlight control is insane right now.&amp;#160; The documentation is very incomplete and there are &lt;strong&gt;NO &lt;/strong&gt;samples (and the IDL is wrong!)&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Background GC on Windows&lt;/strong&gt; - I suspect that this would increase performance in many scenarios. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;The missing GC methods&lt;/strong&gt; - The System.GC class is missing a &lt;strong&gt;PUBLICLY ACCESSIBLE&lt;/strong&gt; GetCollectionCount.&amp;#160; This will help us with profiling.&amp;#160; It's marked as internal now and if you try to access it via reflection or other fancy tricks you get security errors.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;ICorProfilerCallback interface&lt;/strong&gt; - This is my &lt;strong&gt;NUMBER ONE&lt;/strong&gt; FEATURE REQUEST!&amp;#160; This is REQUIRED to create a Silverlight profiler.&amp;#160; Silverlight will NOT be a technology ready for enterprise usage without this.&amp;#160; PERIOD.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Documentation on Silverlight's ETW&lt;/strong&gt; - it's there and it's working in SL2, but I see absolutely zero docs on how to access it.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;The native AGCORE and NPCTRL source code&lt;/strong&gt; - This will aide in performance and feature creation&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;COM interface for hosting the CoreCLR&lt;/strong&gt; - not really a Silverlight feature, but this would be REALLY nice. &lt;/li&gt; &lt;/ul&gt;</description><pubDate>Wed, 21 Jan 2009 21:50:53 -0600</pubDate><a10:link href="http://www.netfxharmonics.com/2009/01/Silverlight-Feature-Requests" /></item></channel></rss>
