Thursday, August 2, 2007

Into .Net 3.5

Last week, Microsoft released Beta 2 of VS 2008 (Orcas) with the .NET framework version 3.5. It is released with a go live license, so you can assume it's feature complete now.
There are some small bugs though, but nevertheless it is a good piece of software to work with.

Linq and Lambda functions
A great new feature is linq, and playing with some thoughts and digging up the old Sequoia View I decided to build a proof of concept of this program in .NET 3.5.

The first step is to assemble a collection of files and directories from a drive. Linq and Lambda queries works quite straightforward here; after filling a large list with a custom FileSystemEntry class, it's quite easy to get data from this list.
In the old days, getting a List entry with a specific property value needed a lot of coding. With the net .NET it's like this:

List<FileSystemEntry> list = GetList();
FileSystemEntry testId =
list.First(listEntry => listEntry.Id == "test");


Or just some plain linq to retrieve some entries form the list in a new smaller list:


List<FileSystemEntry> list = GetList();
var entries = from entry
in list
where entry.ParentId == "test"
select entry;
List<FileSystemEntry> childEntries = entries.ToList();


So basically, you can build with this two code blocks a Parent and a Children property on your class, given a List of objects where you can save your object Id and ParentId. Quite easy and straightforward to use.

In a next post, I will cover building a TreeMap of your disc with XAML and WPF.