C#, Lambdas / Anonomous delegates

List Exporter To CSV

Today I wrote a small utility class that allows any List<T> to be exported to a CSV string or a CSV file using a nice Fluent interface.

This is what it allows:

  1. Take any List<T>, where T could be any class
  2. Let the using code specify what columns should be exported
  3. Use a Fluent API (as they are all the rage these days
  4. Allow auto header named to be obtained using using Expression trees
  5. Allow the the user to supply custom header names
  6. Allow the user to also supply custom format strings for the data being exported
  7. Allow the data to be exported to a CSV file OR allow the data to be exported to a CSV string


And here is an example of how you might use it

//Get it as a String result, using automatic Headers, but formatted Columns, 
//and standard "," seperator
String resultsWithDefaultHeadersAndFormattedColumns = people.GetExporter()
    .AddExportableColumn((x) => x.Age, 
                  customFormatString:"The Person Age Is {0}")
    .AddExportableColumn((x) => x.Name, 
                  customFormatString: "The Persons Name {0}")

If you want to know more you can read the full article over at :



Mole2010 (a mans Visual Debugger)

A Bit Of History

As some of you may recall some time ago (seems like ages) Josh Smith (WPF Guru) wrote a Visual Studio DebuggerVisualizer which he called WoodStock, then some time later Joshs protégé Karl Shifflett wrote a new  DebuggerVisualizer  called Mole which was and still is an extremely useful debugging aid when developing WPF apps.

After Karl wrote the 1st draft of Mole, he quickly contacted Josh and they joined forced to create various flavours/versions of Mole, before being joined by Andrew Smith from Infragistics (whom Josh calls a guru, now Karl calls Josh a guru, so I think you can see what sort of calibre of people are involved with Mole).

So that was then, that was all a about a year ago, many moons have passed since then, so what have team Mole been up to, well it turns out they have been very very busy bunnies indeed….Team Mole have only gone and rewritten Mole entirely. They are calling the new offering Mole 2010.

Now I should point out that the new Mole 2010 is not a free tool, as its predecessors were, but I think the new version is way way better than the old versions, and you can take it for a demo ride before you decide.

I think it is fairly well priced at $49.99, for what it can do for you as a developer.

Now I know it sounds like I am trying to push Mole 2010, which I guess I am in some way, Josh and Karl are both friends and I want their venture to go well. That said I told Josh that I would not be blogging about Mole 2010 until I had taken it for a test ride and was comfortable with what it did and I would only be telling people the truth about it. It just happens that the truth is that it is a very cool useful tool, and I can not think of much that is actually missing.


Enough Enough…..Lets Have A Look At Mole 2010

As I stated Mole 2010 is a Visual Studio (2010) debugger visualizer which you can use instead of the default debugger visualizer, and when you you choose to do that you will get into the Mole 2010 interface.

So say I have some breakpoint as such.


It can be seen that I now get a Mole 2010 option, so let’s accept that and see what we get


This is what looks like when it launches it offers these sorts of view when it first loads

  • VisualTree
  • LogicalTree
  • XAML
  • SnapShot
  • Properties
  • Fields
  • All
  • Favourites

Lets further examine some of these.

VisualTree Area


From here we can drill as far into the VisualTree as we wish, and we can set things to expand or be used as initial node etc etc



The LogicalTree view is the same sort of thing except we only see the items in the logical tree.



This is able to show a snapshot of the xaml as it would be rendered, which you may choose to save as an image. You may also control this updates Auto or Manually.



We are also able to see XAML snippets for selected item in the VisualTree/LogicalTree




This is one of my favourite areas, where we can see what all of the property/fields of certain VisualTree/LogicalTree elements are set to. We can also choose to make certain ones favourites, so they will appear in the favourites list.

We are also able to drill in to collections, as shown above, whilst still maintaining a complete breadcrumb of where we have visited.


For another example lets follow some Style.Triggers





I am sure you will agree that is pretty powerful.

Visual Studio Like IDE

You can actual pin/arrange things just as you would in Visual Studio



More Mole 2010 Information

The creators of mole have written a sponsored article over at codeproject:



Final Word

Anyway that is all I wanted to say about Mole 2010, whether you buy it or not it up to you, I would recommend downloading the demo version and at least taking it for a test drive, it really is quite a cool tool.

C#, Lambdas / Anonomous delegates


The other day I was messing around with an idea I had where I had a object graph of related objects which looked something like this (where each object was an INotifyPropertyChanged object).


And I thought wouldn’t it be nice if I could observer changed from any of those object conveniently, and without the need to hook/unhook when new object were introduced into the object graph.

So I had a think and came up with a bunch of classes that do allow me to observe changes in a chain of objects, and do so in a kind of fault tolerant manner, where replacement objects could be brought into the chain, without any adverse affect to the INPC listeners.

The main class I came up with is called ChainPropertyObserver and can be used as simply as this:

//create INPC model
Person p = new Person();
p.Age = 12;
p.Name = "sacha";
p.Address = new Address() { 
    Addressline1="21 maple street",
    Addressline2 = "Hanover",
    GeoLocation = new GeoLocation 

MyPerson = p;

List<string> personChanges = new List<string>();
List<string> addressChanges = new List<string>();
List<string> geoLocationChanges = new List<string>();

//create observer
ChainPropertyObserver chainPropertyObserver = 
    new ChainPropertyObserver();
    () => MyPerson.Address.GeoLocation, Changed);

//create some INPC listeners
    () => MyPerson,
    () =>
        Console.WriteLine("The Person that changed is now : {0}", 

    () => MyPerson.Address,
    () =>
        Console.WriteLine("The Address that changed is now : {0}", 

    () => MyPerson.Address.GeoLocation,
    () =>
        Console.WriteLine("The GeoLocation that changed is now : {0}", 


.csharpcode, .csharpcode pre
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
background-color: #f4f4f4;
width: 100%;
margin: 0em;
.csharpcode .lnum { color: #606060; }

If you want to know more you can read the full article over at codeproject at this url : http://www.codeproject.com/KB/cs/ChainedObserve.aspx