Xaml for Config
I've been working on a pet project recently and been deeply buried in the configuration of System.Diagnostics. Whenever I find myself writing configuration code at the moment my heart angsts to be back playing in a land filled with Xaml. Here's a sample of configuration for System.Diagnostics today:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="MySource" switchValue="All">
<listeners>
<add name="myListener" />
</listeners>
</source>
<sharedListeners>
<add type="Ukadc.Diagnostics.Listeners.InMemoryTraceListener, Ukadc.Diagnostics" name="myListener">
<filter type="Ukadc.Diagnostics.Filters.MultiFilter, Ukadc.Diagnostics" initializeData="some, nasty, string, full, of, settings"/>
</add>
</sharedListeners>
</system.diagnostics>
</configuration>
Now imagine a world of configuration marked up in Xaml...
<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="http://schemas.microsoft.com/netfx/2009/config"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:Ukadc.Diagnostics;assembly=Ukadc.Diagnostics">
<Configuration.Resources>
<src:InMemoryTraceListener x:Key="myListener">
<src:InMemoryTraceListener.Filters>
<src:MultiFilter Setting1="StronglyTyped" Setting2="Values" />
</src:InMemoryTraceListener.Filters>
</src:InMemoryTraceListener>
</Configuration.Resources>
<Diagnostics>
<Diagnostics.Sources>
<TraceSource x:Name="MySource" SwitchValue="All" Listeners="{StaticResource myListener}" />
<Diagnostics.Sources>
<Diagnostics>
</Configuration>
Type checking, extensibility... oh the joy. Totally invented on the train home, but it would make me a very happy man.

Post By
Josh Twist
1:26 AM
11 Apr 2008
» Next Post:
Working with streams
« Previous Post:
Invoking a Command on a Double Click (or other 'Mouse Gesture')
Comments:
Posted by
David Nelson
@
16 May 2008
3:08 PM
Interestingly, WPF actually makes a lot more sense for application configuration than it does for WPF GUI declaration!