<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Blog</title><link>http://www.westsoft.eu:80/blog</link><description>Blog</description><item><title>"GetMemberName" or "getting rid of (some) magic strings"</title><link>http://www.westsoft.eu:80/blog/2010/11/12/getmembername-or-getting-rid-of-some-magic-strings</link><description>&lt;p&gt;Earlier today I had another discussion() with a co-worker of mine. This discussion related to magic strings and potential ways to get rid of them. I have previously mentioned that I dislike magic strings, but I haven't mentioned why. Nor have I mentioned in which circumstances which I dislike seeing them.&lt;/p&gt;
&lt;h2&gt;When do I use magic strings&lt;/h2&gt;
&lt;p&gt;There are cases where magic strings are pretty useful. An example of this is in communicating between different applications, where strings are more descriptive than using, for example, an integer. Thus, if I send a message from application A to application B telling it to do &amp;ldquo;&amp;lt;action&amp;gt;print&amp;lt;/action&amp;gt;&amp;rdquo; on something, it is a lot more descriptive and easy to debug than if it would be &amp;ldquo;&amp;lt;action&amp;gt;3&amp;lt;/action&amp;gt;&amp;rdquo;. The same goes for the code listening to this message.&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;switch(action)
{
	
	case &amp;ldquo;print&amp;rdquo;:

		//Do the printing
		break;
}&lt;/pre&gt;
&lt;p&gt;it is a lot better than&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;switch(action)
{
	case 3:
		//Do the printing
		break;
}&lt;/pre&gt;
&lt;p&gt;However, I often try to limit the risk of errors, when using magic strings, for example by creating an XSD forcing an enumeration constraint (only allowing the content of the action element to be one of a limited set of values). This also has the benefit of making the message easier to use. (Whether it could still be called a magic string after enforcing an enumeration constraint on the value is a question of definitions, so in general I try to avoid the pitfalls of magic strings.)&lt;/p&gt;
&lt;h2&gt;When do I try to avoid magic strings&lt;/h2&gt;
&lt;p&gt;On the other hand, there are a lot of cases where I believe that magic strings are nothing but evil (although in some cases they may be necessary evil). One example of this is the INotifyPropertyChanged interface. Another such example is throwing ArgumentNullExceptions.&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public class MyClass:INotifyPropertyChanged
{
	public MyClass(IRepository repository)	
	{
		if (repository == null)
		throw new ArgumentNullException(&amp;ldquo;repository&amp;rdquo;);
	}

	private string _name;
	public string Name
	{
		get
		{
			return _name;
		}
		set
		{
			_name = value;
			OnNotifyPropertyChanged(&amp;ldquo;Name&amp;rdquo;);
		}
	}

	public event PropertyChangedEventHandler PropertyChanged;
	protected void OnPropertyChanged(string propertyName)
	{
		if (PropertyChanged != null)
			PropertyChanged(this, new PropertyChangedEventArgs(propertyName);
	}
}&lt;/pre&gt;
&lt;p&gt;What happens when we change the IRepository to be a IDataRepository and therefore also renames the constructor parameter to dataRepository? What happens when we rename the Name property to Title? Well, in most cases we will remember to change the string as well, but every now and then we will forget to change the string. Also, sometimes we will misspell the property name, e.g. writing -&amp;ldquo;Neme&amp;rdquo; instead of &amp;ldquo;Name&amp;rdquo;. Of course, I could unit test all the property setters to make sure that the NotifyPropertyChanged is fired with the correct propertyName. While this might be a good (or bad) idea in and of itself, we still would have to remember to change the contents of the string in the unit test when we rename the property.&lt;/p&gt;
&lt;h2&gt;Expressions to the rescue&lt;/h2&gt;
&lt;p&gt;With C# 3.0 we got lambda expressions, which I am very fond of. Our nice lambda expressions are a lot better as a syntax for writing anonymous methods than what anonymous delegates ever were. The sometimes well-known secret here, however, is that the same lambda expression code could mean two completely different things, depending on the context. Given the following code:&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;DoStuff&amp;lt;string&amp;gt;(stringValue =&amp;gt; Console.WriteLine(stringValue));&lt;/pre&gt;
&lt;p&gt;We would pass completely different things to our DoStuff-method depending on how that method is defined (Which could be compared to sending a constant integer 1 as a parameter to method. If the method takes an integer, the parameter would be compiled as an integer but if the parameter is defined as a double, the compiler would help us and change the 1 to a double with the value 1.0d). If the parameter is defined as an Action&amp;lt;string&amp;gt;, then we would receive a precompiled Action which we could use. If, on the other hand, the parameter is defined as Expression&amp;lt;Action&amp;lt;string&amp;gt;&amp;gt; then we would instead get an expression tree. Using this expression tree, we could compile and execute it if we want to, but we also have the possibility to examine the expression tree (which is very useful, for example when creating an IQueryable or IQbservable).&lt;/p&gt;
&lt;h2&gt;The GetMemberName-method&lt;/h2&gt;
&lt;p&gt;What I would want in the above examples is that if I would rename the property or parameter using the refactoring tools in Visual Studio, the string would automatically be updated as well. And if I, for some reason, would have misspelled or forgot to update the string, I would like a compiler error. The GetMemberName-method will help us achieve this goal.&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public static class ObjectExtensions
{

    public static string GetMemberName(this T obj, Expression&amp;gt; expression)
    {
        if (expression == null)
            obj.GetMemberName(_ =&amp;gt; expression);
        MemberExpression memberExpression = expression.Body as MemberExpression;
        if (memberExpression == null)
            throw new ArgumentException("Expression of type " 
                + expression.Body.Type.ToString() 
                + " is not supported by the GetMemberName method."
                + " Only MemberExpressions are currently supported.", obj.GetMemberName(_ =&amp;gt; expression));
        return memberExpression.Member.Name;
    }
}&lt;/pre&gt;
&lt;p&gt;We could then change our code above to something similar to the following:&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public class MyClass:INotifyPropertyChanged
{
	public MyClass(IRepository repository)	
	{
		if (repository == null)
		throw new ArgumentNullException(this.GetMemberName(_ =&amp;gt; repository));
	}

	private string _name;
	public string Name
	{
		get
		{
			return _name;
		}
		set
		{
			_name = value;
			OnNotifyPropertyChanged(this.GetMemberName(_ =&amp;gt; Name));
		}
	}

	public event PropertyChangedEventHandler PropertyChanged;
	protected void OnPropertyChanged(string propertyName)
	{
		if (PropertyChanged != null)
			PropertyChanged(this, new PropertyChangedEventArgs(propertyName);
	}
}&lt;/pre&gt;
&lt;h2&gt;Tiny drawbacks&lt;/h2&gt;
&lt;p&gt;Of course, for some unfortunate reason, there are no silver bullets which solve every problem, even though this one is at least silver coated. The drawback of using the GetMemberName instead of using a constant string is performance. I have performed very naive performance tests on the GetMemberName-method and it has shown that the method call took up to 30 milliseconds to perform on my laptop (which isn&amp;rsquo;t a very powerful laptop). In almost all cases I believe these milliseconds are worth getting rid of the strings, but if I would set the property 100 times per second this could be a problem (on the other hand, if I update it that frequently, perhaps it isn't a good fit for INotifyPropertyChanged). Therefore, I try to use this approach as often as I can, instead of using unnecessary magic string, and only if it would become a problem, I would consider writing the name as a string.&lt;/p&gt;</description><pubDate>Fri, 12 Nov 2010 17:06:03 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2010/11/12/getmembername-or-getting-rid-of-some-magic-strings</guid></item><item><title>Custom scroll buttons for the ScrollViewer control in Silverlight</title><link>http://www.westsoft.eu:80/blog/2010/11/11/custom-scroll-buttons-for-the-scrollviewer-control-in-silverlight</link><description>&lt;p&gt;Earlier today I had a discussion with a co-worker who needed to replace the default template of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer(VS.95).aspx"&gt;ScrollViewer&lt;/a&gt; control, in order to replace the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.scrollbar(VS.95).aspx"&gt;ScrollBar&lt;/a&gt; with custom buttons. He had found some &lt;a href="http://stackoverflow.com/questions/375291/silverlight-scrollviewer-with-only-buttons"&gt;example of doing this in WPF, but the same sample did not work in Silverlight&lt;/a&gt; (the samples relied on routed command which aren&amp;rsquo;t available in Silverlight) so I decided to write up a sample of my own.&lt;/p&gt;
&lt;p&gt;Disclaimer: The sample is very rudimentary and may not be the best way to achieve this (also the placement of the commands might be questionable). Use the sample at your own risk.&lt;/p&gt;
&lt;p&gt;To begin with, we need a ScrollViewer with some content.&lt;/p&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;Grid x:Name="LayoutRoot" Background="White" Height="100" Width="120"&amp;gt;
    &amp;lt;ScrollViewer&amp;gt;
        &amp;lt;StackPanel&amp;gt;
            &amp;lt;TextBlock Text="Text1"/&amp;gt;
            &amp;lt;TextBlock Text="Text2"/&amp;gt;
            &amp;lt;TextBlock Text="Text3"/&amp;gt;
            &amp;lt;TextBlock Text="Text4"/&amp;gt;
            &amp;lt;TextBlock Text="Text5"/&amp;gt;
            &amp;lt;TextBlock Text="Text6"/&amp;gt;
            &amp;lt;TextBlock Text="Text7"/&amp;gt;
            &amp;lt;TextBlock Text="Text8"/&amp;gt;
            &amp;lt;TextBlock Text="Text9"/&amp;gt;
        &amp;lt;/StackPanel&amp;gt;
    &amp;lt;/ScrollViewer&amp;gt;
&amp;lt;/Grid&amp;gt;&lt;/pre&gt;
&lt;p&gt;Additionally, we will be using a stripped down version of the &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id016"&gt;RelayCommand&lt;/a&gt;. I use a stripped down version since I really don&amp;rsquo;t need any more functionality for this sample.&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public class RelayCommand&amp;lt;T&amp;gt;:ICommand
{
    private Action&amp;lt;T&amp;gt; _action;

    public RelayCommand(Action&amp;lt;T&amp;gt; action)
    {
        this._action = action;
    }

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
        if (!(parameter is T))
            throw new ArgumentException("The parameter must be of type T", "parameter");
        _action((T)parameter);
    }
}&lt;/pre&gt;
&lt;p&gt;The default look of the ScrollViewer control, using the above Xaml looks similar to this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.westsoft.eu/Media/WindowsLiveWriter/CustomscrollbuttonsfortheScrollViewercon_14C89/image_4.png"&gt;&lt;img style="display: inline; border-width: 0px;" title="image" src="http://www.westsoft.eu/Media/WindowsLiveWriter/CustomscrollbuttonsfortheScrollViewercon_14C89/image_thumb_1.png" border="0" alt="The default look of the ScrollViewer control, using the Content we supplied" width="131" height="110" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And our goal is to make it look like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.westsoft.eu/Media/WindowsLiveWriter/CustomscrollbuttonsfortheScrollViewercon_14C89/image_6.png"&gt;&lt;img style="display: inline; border-width: 0px;" title="image" src="http://www.westsoft.eu/Media/WindowsLiveWriter/CustomscrollbuttonsfortheScrollViewercon_14C89/image_thumb_2.png" border="0" alt="The modified look of the ScrollViewer control, using buttons instead of the ScrollBar, which we have as our aim" width="110" height="105" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Quite an improvement, right?&lt;/p&gt;
&lt;p&gt;I admit that it might not be prettiest design for my custom scroll buttons. To my defence I will say that beauty is not the aim of this post and&amp;hellip; well, at least it works.&lt;/p&gt;
&lt;p&gt;To get the ScrollViewer to look like what we want, we start by changing the declaration of the ScrollViewer to start using a custom template (if you do this in production code, you might want to define it as a style and set the Template property to be your ContentTemplate, especially since you will probably want to set other properties as well, but in order to keep the code a little shorter here, we&amp;rsquo;ll just set the template directly) which we will define later. The new declaration of the ScrollViewer should be:&lt;/p&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;ScrollViewer Template="{StaticResource MyScrollViewer}"&amp;gt;
...&lt;/pre&gt;
&lt;p&gt;The next step is to create the actual Template that we have just referenced. In our template, we&amp;rsquo;ll create two &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.repeatbutton(VS.95).aspx"&gt;RepeatButton&lt;/a&gt;s (using RepeatButtons instead of Buttons allows the user to keep the button pressed to keep scrolling until released), to serve as up and down buttons, and between them we&amp;rsquo;ll place the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollcontentpresenter(VS.95).aspx"&gt;ScrollContentPresenter&lt;/a&gt; (which will display the content of the ScrollViewer control, i.e. the TextBlocks).&lt;/p&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;ControlTemplate x:Key="MyScrollViewer" TargetType="ScrollViewer"&amp;gt;
    &amp;lt;StackPanel Width="100"&amp;gt;
        &amp;lt;RepeatButton Content="Up" Command="{Binding ScrollUpCommand, ElementName=_this}"
		CommandParameter="{Binding ElementName=ScrollContentPresenter}"/&amp;gt;
        &amp;lt;ScrollContentPresenter Height="50" x:Name="ScrollContentPresenter"/&amp;gt;
        &amp;lt;RepeatButton Content="Down" Command="{Binding ScrollDownCommand, ElementName=_this}"
		CommandParameter="{Binding ElementName=ScrollContentPresenter}"/&amp;gt;
    &amp;lt;/StackPanel&amp;gt;
&amp;lt;/ControlTemplate&amp;gt;&lt;/pre&gt;
&lt;p&gt;So, what is the ScrollUpCommand used in the code above? The ScrollUpCommand, as well as the ScrollDownCommand, is defined in the code behind of the control, using the following code:&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public ICommand ScrollUpCommand
{
	get
	{
		return new RelayCommand&amp;lt;ScrollContentPresenter&amp;gt;(scroll =&amp;gt; scroll.LineUp());
	}
}

public ICommand ScrollDownCommand
{
	get
	{
		return new RelayCommand&amp;lt;ScrollContentPresenter&amp;gt;(scroll =&amp;gt; scroll.LineDown());
	}
}&lt;/pre&gt;
&lt;p&gt;And there we have it, our nice little ScrollViewer without the default ScrollBar. The secret sauce lies in the CommandParameter, sending the ScrollContentPresenter which we want to scroll as a parameter to the command when it executes. Have fun with the code! Here is the full code for the sample:&lt;/p&gt;
&lt;p&gt;MainPage.xaml:&lt;/p&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;UserControl x:Class="SilverlightApplication11.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" x:Name="_this"&amp;gt;
    &amp;lt;UserControl.Resources&amp;gt;
        &amp;lt;ControlTemplate x:Key="MyScrollViewer" TargetType="ScrollViewer"&amp;gt;
            &amp;lt;StackPanel Width="100"&amp;gt;
                &amp;lt;RepeatButton Content="Up" Command="{Binding ScrollUpCommand, ElementName=_this}" 
			CommandParameter="{Binding ElementName=ScrollContentPresenter}"/&amp;gt;
                &amp;lt;ScrollContentPresenter Height="50" x:Name="ScrollContentPresenter"/&amp;gt;
                &amp;lt;RepeatButton Content="Down" Command="{Binding ScrollDownCommand, ElementName=_this}" 
			CommandParameter="{Binding ElementName=ScrollContentPresenter}"/&amp;gt;
            &amp;lt;/StackPanel&amp;gt;
        &amp;lt;/ControlTemplate&amp;gt;
    &amp;lt;/UserControl.Resources&amp;gt;
    &amp;lt;Grid x:Name="LayoutRoot" Background="White" Height="100" Width="120"&amp;gt;
        &amp;lt;ScrollViewer Template="{StaticResource MyScrollViewer}"&amp;gt;
            &amp;lt;StackPanel&amp;gt;
                &amp;lt;TextBlock Text="Text1"/&amp;gt;
                &amp;lt;TextBlock Text="Text2"/&amp;gt;
                &amp;lt;TextBlock Text="Text3"/&amp;gt;
                &amp;lt;TextBlock Text="Text4"/&amp;gt;
                &amp;lt;TextBlock Text="Text5"/&amp;gt;
                &amp;lt;TextBlock Text="Text6"/&amp;gt;
                &amp;lt;TextBlock Text="Text7"/&amp;gt;
                &amp;lt;TextBlock Text="Text8"/&amp;gt;
                &amp;lt;TextBlock Text="Text9"/&amp;gt;
            &amp;lt;/StackPanel&amp;gt;
        &amp;lt;/ScrollViewer&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/UserControl&amp;gt;
&lt;/pre&gt;
&lt;p&gt;MainPage.xaml.cs&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;using System.Windows.Controls;
using System.Windows.Input;

namespace SilverlightApplication11
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        public ICommand ScrollUpCommand
        {
            get
            {
                return new RelayCommand&amp;lt;ScrollContentPresenter&amp;gt;(scroll =&amp;gt; scroll.LineUp());
            }
        }

        public ICommand ScrollDownCommand
        {
            get
            {
                return new RelayCommand&amp;lt;ScrollContentPresenter&amp;gt;(scroll =&amp;gt; scroll.LineDown());
            }
        }
    }
}&lt;/pre&gt;
&lt;p&gt;RelayCommand.cs&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;using System;
using System.Windows.Input;

namespace SilverlightApplication11
{
    public class RelayCommand&amp;lt;T&amp;gt;:ICommand
    {
        private Action&amp;lt;T&amp;gt; _action;

        public RelayCommand(Action&amp;lt;T&amp;gt; action)
        {
            this._action = action;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            if (!(parameter is T))
                throw new ArgumentException("The parameter must be of type T", "parameter");
            _action((T)parameter);
        }
    }
}&lt;/pre&gt;</description><pubDate>Thu, 11 Nov 2010 22:59:06 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2010/11/11/custom-scroll-buttons-for-the-scrollviewer-control-in-silverlight</guid></item><item><title>State Machine in WF vNext</title><link>http://www.westsoft.eu:80/blog/2010/10/30/state-machine-in-wf-vnext</link><description>&lt;p&gt;About a year and a half ago, I wrote &lt;a href="http://www.westsoft.eu/blog/2009/05/11/no-state-machine-in-wf4"&gt;a post regarding the fact that they removed the State Machine when rewriting Workflow Foundation (WF) to create WF4&lt;/a&gt;. When listening to one of the PDC 2010 presentations regarding WF vNext, I found out that one of the news for the next version of WF was the State Machine. The other news coming with vNext, directly from the list in the presentation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;State Machine &lt;/li&gt;
&lt;li&gt;C# Expressions &lt;/li&gt;
&lt;li&gt;Versioning &lt;/li&gt;
&lt;li&gt;Dynamic Update &lt;/li&gt;
&lt;li&gt;Enhanced Workflow Designer &lt;/li&gt;
&lt;li&gt;New Activities 
&lt;ul&gt;
&lt;li&gt;Database, SendMail, REST Client, &amp;hellip;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;WCF Workflow Service Improvements 
&lt;ul&gt;
&lt;li&gt;Security, Contract First&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Partial Trust&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can see the whole presentation at: &lt;a title="http://player.microsoftpdc.com/Session/3b87c17b-a218-40d3-984f-78a012331dee/1237" href="http://player.microsoftpdc.com/Session/3b87c17b-a218-40d3-984f-78a012331dee/1237"&gt;http://player.microsoftpdc.com/Session/3b87c17b-a218-40d3-984f-78a012331dee/1237&lt;/a&gt;&lt;/p&gt;</description><pubDate>Sat, 30 Oct 2010 16:43:23 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2010/10/30/state-machine-in-wf-vnext</guid></item><item><title>No hibernation on Windows 7 when booting from VHD</title><link>http://www.westsoft.eu:80/blog/2009/09/02/no-hibernation-on-windows-7-when-booting-from-vhd</link><description>&lt;p&gt;Ever since I heard that Windows 7 would include a boot loader which supported &lt;a href="http://www.hanselman.com/blog/LessVirtualMoreMachineWindows7AndTheMagicOfBootToVHD.aspx"&gt;booting directly from a VHD file&lt;/a&gt; I have been eagerly awaiting the arrival of Windows 7. For quite some time I have been doing development on virtual machines instead of non-virtual machines in order to be able to isolate the development environment for the different projects, so the boot from VHD option suits me perfectly since it removes the great performance loss of running a virtualisation software on top of an operating system.&lt;/p&gt;
&lt;p&gt;I am also a big user of the Hibernate option, both in my private development projects and during work projects. Any time that I need to shut down when in the middle of something (read: not completely finished with something), I always use the Hibernate option in order to save a lot of time when starting again (I won&amp;rsquo;t have to start up the programs and I don&amp;rsquo;t have to try and remember when I stopped working last time, it&amp;rsquo;s right there).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Therefore, after running Windows 7 for a short time, I felt the need to be able to hibernate again, but I couldn&amp;rsquo;t find the option to turn it on. Thinking that they had just moved it for Windows 7 (it&amp;rsquo;s their right, after all), I tried &amp;lt;insert favourite search engine here&amp;gt;ing it. Unfortunately, what I found on the &lt;a href="http://blogs.technet.com/virtualization/archive/2009/05/14/native-vhd-support-in-windows-7.aspx"&gt;Windows Virtualization Team Blog&lt;/a&gt; was the following message:&lt;/p&gt;
&lt;div class="quote"&gt;
&lt;p&gt;&amp;ldquo;&lt;/p&gt;
&lt;p&gt;Native VHD boot in this release does not support BitLocker, or hibernation (which includes resuming from hibernate).&lt;/p&gt;
&lt;p&gt;&amp;ldquo;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The lack of the hibernation option is actually so big for me that I will probably remove my VHD-boot and go back to either running without virtualisation (in which case I will run into problems later on) or just use some desktop virtualisation software (in which case I will have a loss of performance). They do leave some hope for me there, though, when writing that &amp;ldquo;in this release&amp;rdquo;-part. Next step for me is to evaluate the option of installing Windows Server 2008 R2 on my laptop and running HyperV. I just need to check on the performance and the ability to hibernate first.&lt;/p&gt;</description><pubDate>Wed, 02 Sep 2009 11:09:16 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2009/09/02/no-hibernation-on-windows-7-when-booting-from-vhd</guid></item><item><title>Creating a Custom Part Catalog for the Managed Extensibility Framework</title><link>http://www.westsoft.eu:80/blog/2009/06/30/creating-a-custom-part-catalog-for-the-managed-extensibility-framework</link><description>&lt;p&gt;I'm very fond of the &lt;a href="http://mef.codeplex.com/"&gt;Managed Extensibility Framework&lt;/a&gt; (MEF). MEF makes it very easy to create extendable and composable applications. At &lt;a href="http://www.microsoft.com/events/teched2009/"&gt;TechEd in Los Angeles this year&lt;/a&gt; &lt;a href="http://www.managed-world.com"&gt;Jason Olson&lt;/a&gt; held a presentation on opening up an application for extendability with MEF. During his session he presented a sample of a network status aware catalog, which seemed very easy to create and also felt as a very good example of a custom part catalog. Also, I haven't been able to find a good example of how to create a custom part catalog which supports recomposable imports (which is embarrasingly easy, once you know which interface to implement).Unfortunately, I haven't been able to find his code anywhere on the internet and thus decided to create a catalog inspired by his.&lt;/p&gt;
&lt;p&gt;&lt;span class="update"&gt;UPDATE:&lt;/span&gt;When I started writing this post (it took a while to get the focus to complete it), I couldn't find information on creating custom catalogs, but when looking again I found that &lt;a href="http://www.codeplex.com/MEF/Wiki/View.aspx?title=Filtering%20Catalogs"&gt;an example has been created on the MEF codeplex page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Disclaimer: All code in this post is &lt;a href="http://haacked.com/archive/0001/01/01/code-sample-taxonomy.aspx"&gt;Demo code&lt;/a&gt; and is supposed to be taken as such. Feel free to use the code in any manner, but &lt;a href="http://www.codinghorror.com/blog/archives/001268.html"&gt;always be sure you understand what copied code does and how it is done&lt;/a&gt;. I do not make any guarantees that code in my posts are production ready.&lt;/p&gt;
&lt;h2&gt;Introducing the Network Status Aware Catalog&lt;/h2&gt;
&lt;p&gt;The network status aware catalog is a filter catalog which makes its' decisions based on whether or not a network connection could be found. The &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getisnetworkavailable.aspx"&gt;MSDN article on the NetworkInterface.GetIsNetworkAvailable()-method&lt;/a&gt; (the method that the catalog will use to determine whether or not it has a network) defines a network availablility as:&lt;/p&gt;
&lt;div class="quote"&gt;"A network connection is considered to be available if any network interface is marked "up" and is not a loopback or tunnel interface."&lt;/div&gt;
&lt;p&gt;This does not guarantee a connection to the internet, but it is enough for our demo code.&lt;/p&gt;
&lt;p&gt;Giving the catalog the functionality to support &lt;a href="http://mef.codeplex.com/Wiki/View.aspx?title=Recomposition"&gt;recomposition&lt;/a&gt; allows imports to state that composition containers are allowed to exchange imported parts when some state change occurs in the catalog (or the catalog for some other reason decides that it is time to perform recomposition).&lt;/p&gt;
&lt;h2&gt;The Network Status enum&lt;/h2&gt;
&lt;p&gt;Since I really hate magic strings, I will be using a simple enum to define network statuses.&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  public enum NetworkStatus
  {
      Online,
      Offline
  }
&lt;/pre&gt;
&lt;p&gt;A simple enum, but beyond doubt complex enough.&lt;/p&gt;
&lt;h2&gt;Creating a filtering Part Catalog&lt;/h2&gt;
&lt;p&gt;It is very easy to create a filtering for MEF is very easy. Just inherit from the ComposablePartCatalog class and implement the abstract property called Parts. Since we want a filtering part catalog, we will also add a constructor which receives a ComposablePartCatalog as a parameter.&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  public class NetworkStatusAwareCatalog : ComposablePartCatalog
  {
      private ComposablePartCatalog _composablePartCatalogToFilter;
      public NetworkStatusAwareCatalog(ComposablePartCatalog composablePartCatalogToFilter)
      {
          this._composablePartCatalogToFilter = composablePartCatalogToFilter;
      }

      public override IQueryable&amp;lt;ComposablePartDefinition&amp;gt; Parts
      {
          get { return _composablePartCatalogToFilter.Parts; }
      }
  }
&lt;/pre&gt;
&lt;p&gt;Since the Parts property is an &lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.iqueryable.aspx"&gt;IQueryable&lt;/a&gt;, it is very easy to use link to add the filtering we want (we will be implementing the missing methods in a short while).&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  public override IQueryable&amp;lt;ComposablePartDefinition&amp;gt; Parts
  {
      get { return _catalogToFilter.Parts.Where(p =&amp;gt; !IsNetworkStatusAware(p)
                       || DoesCurrentNetworkStatusMatchPartNetworkStatus(p)); }
  }
&lt;/pre&gt;
&lt;p&gt;This looks very nice so far. However, as we can see we need some way to know if a part is &amp;ldquo;network status aware&amp;rdquo; or not (that is, whether a part should only be used when the network status is either online or offline). This can be used by adding PartMetaData on Exported types. In order to understand how it would work, we here create two controls to export, one which should only be used when the network is in online status and one which should only be used in offline status (Again, I really dislike the magic string here, but as &lt;a href="http://haacked.com/archive/0001/01/01/code-sample-taxonomy.aspx"&gt;Demo code&lt;/a&gt; the strings here actually make the code in the post shorter and we will thus use it anyway).&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  [Export("NetworkStatusAwareControl", typeof(UIElement))]
  [PartMetadata("NetworkStatus", NetworkStatus.Online)]
  public partial class ControlWhichShouldOnlyBeUsedWhenNetworkIsOnline : UserControl
  {
      //The content of this UserControl is not interesting in this post and has thus been omitted.
  }

  [Export("NetworkStatusAwareControl", typeof(UIElement))]
  [PartMetadata("NetworkStatus", NetworkStatus.Offline)]
  public partial class ControlWhichShouldOnlyBeUsedWhenNetworkIsOffline : UserControl
  {
      //The content of this UserControl is not interesting in this post and has thus been omitted.
  }
&lt;/pre&gt;
&lt;p&gt;Accessing this part metadata is very easy to do in the ComposablePartCatalog and thus implementing the two methods IsNetworkStatusAware and DoesCurrentNetworkStatusMatchPartNetworkStatus will now be very easy (we also add a private variable called _currentNetworkStatus which, of course, should contain the current network status).&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  private NetworkStatus _currentNetworkStatus = NetworkStatus.Offline;
  private bool IsNetworkStatusAware(ComposablePartDefinition part)
  {
      return part.Metadata.ContainsKey(MetadataKeys.NetworkStatus);
  }

  private bool DoesCurrentNetworkStatusMatchPartNetworkStatus(ComposablePartDefinition part)
  {
      return part.Metadata["NetworkStatus"] is NetworkStatus
          &amp;amp;&amp;amp; CurrentNetworkStatusMatches((NetworkStatus)part.Metadata["NetworkStatus"]);
  }

  private bool CurrentNetworkStatusMatches(NetworkStatus status)
  {
      if (Enum.IsDefined(typeof(NetworkStatus), status))
          return status == _currentNetworkStatus;
      else
          return false;
  }
&lt;/pre&gt;
&lt;p&gt;So what do we have now? We have created our custom ComposablePartCatalog and it filters the available Parts (if they are &amp;ldquo;network status aware&amp;rdquo;) based on the &amp;ldquo;current&amp;rdquo; network status.&lt;/p&gt;
&lt;h2&gt;What about recomposition?&lt;/h2&gt;
&lt;p&gt;We have only two things left to support in our simple network status aware catalog. It is knowing the current network status and we also need to support recomposition. One step at a time. Lets start with supporting recomposition. As I mentioned previously, supporting recomposition is very easy when you know which interface to implement, since the interface only defines one single event; the Changed event.&lt;/p&gt;
&lt;p&gt;We start by adding the implementation of the interface to the class definition as well as implementing the event and adding a protected OnChanged method.&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  public class NetworkStatusAwareCatalog : ComposablePartCatalog, INotifyComposablePartCatalogChanged
  {
      //The rest of the class is the same as it was previously and has been emitted.
      public event EventHandler&amp;lt;ComposablePartCatalogChangedEventArgs&amp;gt; Changed;
      protected void OnChanged()
      {
          var changedEvent = Changed;
          if (changedEvent != null)
              changedEvent(this, new ComposablePartCatalogChangedEventArgs(this.Parts));
      }
  }
&lt;/pre&gt;
&lt;p&gt;Only one more thing to do now; updating our "current network status" when the network status availability changes and calling the OnChanged method when things change. To our help comes the NetworkInterface class and the NetworkChange class. The NetworkInterface class has the method GetIsNetworkAvailable and the NetworkChange class has the event NetworkAvailabilityChanged (in a Silverlight test application I used the NetworkAddressChanged event instead, which seemed to work just fine for this purpose).&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  private void CheckNetworkStatus()
  {
      var previousNetworkStatus = _currentNetworkStatus;
      if (NetworkInterface.GetIsNetworkAvailable())
          _currentNetworkStatus = NetworkStatus.Online;
      else
          _currentNetworkStatus = NetworkStatus.Offline;
      if (_networkStatus != previousNetworkStatus)
          OnChanged();
  }
&lt;/pre&gt;
&lt;p&gt;With this method ready, we just need to call it once initially and then every time the network availability changes (or address changes). The constructor would be a perfect place to add these calls.&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  public NetworkStatusAwareCatalog(ComposablePartCatalog composablePartCatalogToFilter)
  {
      this._composablePartCatalogToFilter = composablePartCatalogToFilter;
      NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
      CheckNetworkStatus();
  }

  private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
  {
      CheckNetworkStatus();
  }
&lt;/pre&gt;
&lt;h2&gt;Using the network status aware catalog&lt;/h2&gt;
&lt;p&gt;Have we done all this work for nothing since we still haven&amp;rsquo;t used this catalog at all? No, of course not. Using it is extremely simple.&lt;/p&gt;
&lt;p&gt;In my test application, which was done in Silverlight, I had ContentControl bound to a property of a custom UserControl. The property of the UserControl is a dependency property (in order to support binding, not necessary for MEF).&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  [Import("NetworkStatusAwareControl", typeof(UIElement), AllowRecomposition = true)]
  public UIElement ChildControls
  {
      get { return (UIElement)GetValue(ChildControlsProperty); }
      set { SetValue(ChildControlsProperty, value); }
  }
&lt;/pre&gt;
&lt;p&gt;Observe that we have specified in the attribute to the property to import using the string &amp;ldquo;NetworkStatusAwareControl&amp;rdquo; with the type UIElement (the string and type matches those of the Export) and that this is where we say AllowRecomposition = true. Creating the UserControl and allowing the container to do its composition magic is now very easy (since my application was a Silverlight application, this code is taken from the application startup event handler of the App class).&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;  var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
  var container = new CompositionContainer(new NetworkStatusAwareCatalog(catalog));
  this.RootVisual = container.GetExportedObject&amp;lt;FrameworkElement&amp;gt;(ExportConstants.RootVisual);
&lt;/pre&gt;</description><pubDate>Tue, 30 Jun 2009 19:43:37 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2009/06/30/creating-a-custom-part-catalog-for-the-managed-extensibility-framework</guid></item><item><title>LINQ to XSD is now open source</title><link>http://www.westsoft.eu:80/blog/2009/06/05/linq-to-xsd-is-now-open-source</link><description>&lt;p&gt;An interesting project that &lt;a href="http://www.westsoft.eu/blog/archive/2009/05/07/linq-to-xsd.aspx"&gt;I&amp;rsquo;ve previously written about is the LINQ to XSD project&lt;/a&gt;. It&amp;rsquo;s not a LINQ Provider but it is a tool for generating code to work with XML files in a type safe manner (which will give you the power of LINQ to Objects with the type safe data objects).&lt;/p&gt;
&lt;p&gt;Last time I wrote about the LINQ to XSD tool, I had received an answer to an e-mail query to the team. They said that they were looking at &amp;ldquo;ways to further the LINQ to XSD technology for its user community.&amp;rdquo; Now, they have done just that. &lt;a href="http://linqtoxsd.codeplex.com/"&gt;The LINQ to XSD project can now be found on Codeplex.&lt;/a&gt; Now the community (that&amp;rsquo;s us!) can further the LINQ to XSD technology for ourselves. My thanks to the team at Microsoft for this!&lt;/p&gt;</description><pubDate>Fri, 05 Jun 2009 14:51:06 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2009/06/05/linq-to-xsd-is-now-open-source</guid></item><item><title>TechEd 2009 Keynote - Problem Steps Recorder and BootManager support for booting from VHD</title><link>http://www.westsoft.eu:80/blog/2009/05/12/teched-2009-keynote---problem-steps-recorder-and-bootmanager-support-for-booting-from-vhd</link><description>&lt;p&gt;At the TechEd 2009 keynote today, &lt;a href="http://www.microsoft.com/presspass/exec/veghte/"&gt;Bill Veghte, VP for the Windows Business&lt;/a&gt;, announced that Windows 7 will be released before holidays (Christmas) this year (subscribers will probably get it before that). The same goes for Windows Server 2008 R2, which means that we will see both these systems making great Christmas presents for geeks everywhere.&lt;/p&gt;
&lt;p&gt;When Mark Russinovich took over, he presented two things I found &lt;strong&gt;very&lt;/strong&gt; interesting regarding Windows 7; the &lt;a href="http://www.istartedsomething.com/20090111/windows-7-problem-steps-recorder-miracle-tool/"&gt;Problem Steps Recorder&lt;/a&gt; and &lt;a href="http://edge.technet.com/Media/Windows-7-Boot-from-VHD/"&gt;the possibility to boot directly from VHD&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The Problem Steps Recorder will make life easier for geeks everywhere when users (be it customers or friends or family) can record when errors happen instead of having a less-than-computer-savvy (not always the case, of course, but at least most often) person try to explain the steps to reproduce the error.&lt;/p&gt;
&lt;p&gt;Giving the BootManager support for booting directly from a VHD really seems like a great thing. I often suggest doing all development within virtual machines since this will isolate environments and keep new projects from messing with the environment of old projects. Being able to boot directly from the different VHDs would mean that the performance loss of running the development environment as a guest OS in Virtual PC or VMWare which in turn is running on a host OS would be gone. The isolated development environment should also be able to benefit from all the real hardware of the computer, instead of relying on the virtualised hardware. There are of course drawbacks to this (e.g. installing drivers to specific hardware makes the VHD more damaged by a move between computers), but I think that eliminating the need to run two OSes (running HyperV or ESX or &amp;lt;insert own favourite here&amp;gt; could of course also be a viable solution, but it would take a whole lot more setting up and managing, I would guess) makes it all worth it.&lt;/p&gt;
&lt;p&gt;When it came to the server side, Iain McDonald mentioned (among a lot of other things, of course) a small but still nice feature of Windows Server 2008 R2, &lt;a href="http://blogs.technet.com/filecab/archive/2009/05/11/windows-server-2008-r2-file-classification-infrastructure-managing-data-based-on-business-value.aspx"&gt;the File Classification Infrastructure&lt;/a&gt;. Also a nice addition to this is the addition of OCR-technology into Windows Server 2008 R2 which allows it to search even in text within images.&lt;/p&gt;</description><pubDate>Tue, 12 May 2009 08:50:35 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2009/05/12/teched-2009-keynote---problem-steps-recorder-and-bootmanager-support-for-booting-from-vhd</guid></item><item><title>No state machine in WF4</title><link>http://www.westsoft.eu:80/blog/2009/05/11/no-state-machine-in-wf4</link><description>&lt;p&gt;I attended a &lt;a href="http://www.msteched.com/teched/default.aspx"&gt;TechEd&lt;/a&gt; pre-conference session today, in which one of the presenters, &lt;a href="http://www.theworkflowelement.com/"&gt;Zoiner Tejada&lt;/a&gt;, said something that surprised me. There will be no state machine workflows in Workflow Foundation in .NET 4.0.&lt;/p&gt;
&lt;p&gt;However, we need not despair in its absence. WF in .NET 4.0 contains a hybrid workflow, which lies somewhere between the still existing Sequential Workflow and the late State Machine, the Flowchart.&lt;/p&gt;
&lt;p&gt;I had planned on writing a short introduction to the Flowchart, but I found a nice &lt;a href="http://blog.batfishsolutions.com/2009/03/wf-40-part-2-flowchart-workflow.html"&gt;introductory article to the Flowchart workflow&lt;/a&gt; and realised that linking to that article might be a better idea since it spares me the job. :)&lt;/p&gt;
&lt;p&gt;As a side note, Mr Tejada also hinted that Microsoft might release an out of band release which would contain the State Machine workflow for .NET 4.0, but he was very specific that as of yet, nothing is certain in that regard.&lt;/p&gt;</description><pubDate>Mon, 11 May 2009 04:22:58 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2009/05/11/no-state-machine-in-wf4</guid></item><item><title>LINQ to XSD</title><link>http://www.westsoft.eu:80/blog/2009/05/07/linq-to-xsd</link><description>&lt;p&gt;&lt;span class="update"&gt;UPDATE:&lt;/span&gt; &lt;a href="http://www.westsoft.eu/blog/archive/2009/06/05/linq-to-xsd-is-now-open-source.aspx"&gt;LINQ to XSD has now been released as open source.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A long time ago in a galaxy far, far away&amp;hellip; That&amp;rsquo;s not really the case, but it&amp;rsquo;s not far from it. In early 2007 I first read about &lt;a href="http://blogs.msdn.com/xmlteam/archive/2006/11/27/typed-xml-programmer-welcome-to-linq.aspx"&gt;the LINQ to XSD project&lt;/a&gt; which Microsoft (or rather, it&amp;rsquo;s &lt;a href="http://blogs.msdn.com/xmlteam/"&gt;xml team&lt;/a&gt;) was working on. I haven&amp;rsquo;t heard much news about this project since then, so I decided to write an e-mail to the xml team. It didn&amp;rsquo;t take long for them to answer my query (they seem to be similar to DLINQ in this manner) in a very short and concise manner. I&amp;rsquo;m not really sure about how I should interpret the response, however.&lt;/p&gt;
&lt;p&gt;My question was (very compressed so you don&amp;rsquo;t have to read my entire e-mail): &amp;ldquo;I haven&amp;rsquo;t seen any news about LINQ to XSD in a long while. Is it a dead project? If it&amp;rsquo;s dead, could you give it to the community to continue?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The answer I received from Pawel Kadluczka was:&lt;/p&gt;
&lt;div class="quote"&gt;
&lt;p&gt;&amp;ldquo;&lt;/p&gt;
&lt;p&gt;Hi Robert,&lt;/p&gt;
&lt;p&gt;We're currently looking at ways in which we might further the LINQ to XSD technology for its user community. We don't have anything to announce quite yet.&lt;/p&gt;
&lt;p&gt;Thanks &lt;br /&gt;Pawel&lt;/p&gt;
&lt;p&gt;&amp;ldquo;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Well, the happy note here is that the project isn&amp;rsquo;t dead. The sad part is that I didn&amp;rsquo;t succeed in prying more information by nagging. :) I guess patience is the key, then. My thanks to Pawel for the e-mail!&lt;/p&gt;
&lt;h3&gt;What is LINQ to XSD?&lt;/h3&gt;
&lt;p&gt;I do so love type safety on my data classes. When I load data, be it from a database, a form post or an xml file, I do not want to touch things with Magic Strings. The best part? If I would correct a spelling mistake or change the name of an element, I would get a compile time error instead of run time. Therefore I am very much into OR Mappers and XSD class generators.&lt;/p&gt;
&lt;p&gt;However, I have never been very fond of the xsd.exe application which generates .NET (C# or VB.NET) classes from an XSD file. There are several reasons for this, but my main complains is that it is a one way conversion (there is not enough information in the generated classes to be able to recreate the XSD file from them) and that I can&amp;rsquo;t use the generated classes to validate that the data in the structures actually satisfies the constraints of the XSD file. An example of this would be a string constrained to the length of 20 characters in the XSD. The code generated by xsd.exe does not contain the constraint information and I can thus not (easily) verify whether or not the data in my objects are valid according to the constraints in the XSD file.&lt;/p&gt;
&lt;p&gt;On a white horse, riding in the sunset with a glass of milk in it&amp;rsquo;s hands, &amp;ldquo;LINQ to XSD&amp;rdquo; comes to the rescue. LINQ to XSD, like xsd.exe is a tool which generates classes from an XSD file. LINQ to XSD is (or will be) more integrated into Visual Studio than xsd.exe is. Just set the build action of the XSD file to use LINQ to XSD and it will re-generate the classes for you when you compile your project. This also means that once you have set the build action and compiled your project you will get the wonderful thing called Intellisense. Also, LINQ to XSD (not surprisingly, due to the name) also makes the resulting classes very easy to use efficiently with LINQ to Objects (and further also &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163329.aspx"&gt;PLINQ&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;An example of using LINQ to XSD and then LINQ to Objects over the generated objects would give something code like the following (Since I cannot install the LINQ to XSD alpha at the moment, I&amp;rsquo;ll just steal the example the xml team is using in the &lt;a href="http://download.microsoft.com/download/1/5/a/15a59e5d-464e-438e-bc59-9846ab787fd5/LinqToXsdOverview_November_2006.doc"&gt;LINQ to XSD overview document&lt;/a&gt;)&lt;/p&gt;
&lt;pre class="csharp:nocontrols"&gt;(from item in purchaseOrder.Item
 select item.Price * item.Quantity).Sum(); &lt;/pre&gt;
&lt;p&gt;which would sum the price of all items in the following XML file.&lt;/p&gt;
&lt;pre class="xml:nocontrols"&gt;&amp;lt;purchaseOrder&amp;gt;
 &amp;lt;item&amp;gt;
  &amp;lt;price&amp;gt;12&amp;lt;/price&amp;gt;
  &amp;lt;quantity&amp;gt;2&amp;lt;/quantity&amp;gt;
 &amp;lt;/item&amp;gt;
 &amp;lt;item&amp;gt;
  &amp;lt;price&amp;gt;24&amp;lt;/price&amp;gt;
  &amp;lt;quantity&amp;gt;1&amp;lt;/quantity&amp;gt;
 &amp;lt;/item&amp;gt;
 &amp;lt;item&amp;gt;
  &amp;lt;price&amp;gt;17&amp;lt;/price&amp;gt;
  &amp;lt;quantity&amp;gt;2&amp;lt;/quantity&amp;gt;
 &amp;lt;/item&amp;gt;
&amp;lt;/purchaseOrder&amp;gt;&lt;/pre&gt;
&lt;p&gt;and given that the XSD file would specify the price element and the quantity element as integers, the result of the call would be 82. And all this without any explicit casting in the code that uses the loaded data.&lt;/p&gt;</description><pubDate>Thu, 07 May 2009 23:58:20 GMT</pubDate><guid isPermaLink="true">http://www.westsoft.eu:80/blog/2009/05/07/linq-to-xsd</guid></item></channel></rss>
