Archive for October, 2007

Returned from Redmond

It’s been an overwhelming few days listening and interacting with bright people from the .NET community and within Microsoft itself (wish I could say more but I can’t). Here are just a few of those names, I wish I knew them all but I was so busy listening to what they had to say I often forgot to ask for a card:

And from the Microsoft side of the fence

Congratulations go out to Rob Conery who is now getting paid by Microsoft to work on SubSonic!

How cool is that!

[)amien

Extension methods illustrated

Extension methods are a great new feature in the .NET Framework 3.5 that let you write new methods that appear to be part of existing classes without the need to subclass or modify them.

We can explain this in simple terms with an example. Here is a useful routine that takes a string and returns what it finds between two other strings that works just fine with .NET 2.0 and .NET 1.1.

public static string Between(string value, string start, string end) {
    int startIndex = value.IndexOf(start, StringComparison.CurrentCultureIgnoreCase);
    if (startIndex == -1)
        return "";
    startIndex += start.Length;

    int endIndex = value.IndexOf(end, startIndex, StringComparison.CurrentCultureIgnoreCase);
    if (endIndex == -1)
        return "";

    return value.Substring(startIndex, endIndex-startIndex);
}

If this method belonged to a static StringUtilities class then you could use it like this:

string newString = StringUtilities.Between(inputString, startingString, endingString);

The problem is knowing that the StringUtilities class within the project you are working on and until you know that IntelliSense can’t even kick in. What would be nice is to add this to the String class but of course we can’t because String is sealed and besides methods everywhere create String classes and not instances of your subclass.

What would be really cool is if Visual Studio and .NET could just realise that this method is static and takes a string parameter as it’s first parameter and let it just appear as another method on the String class and just call StringUtilities behind the scenes.

That is exactly what the extension methods in .NET 3.5 achieve.

All we need to do is put this in front of the first parameter which will let VS and the compiler know that this method should appear as if it is a method against the type of that first parameter. The method must be static and visible to the code and curiously the class itself must also be static. Our signature now appears as:

public static string Between(string this value, string start, string end)

To call the method we simply press . after our string and IntelliSense displays all the usual methods and properties of the String class and any extension methods it can find in your project too which now includes our Between method giving us:

string newString = inputString.Between(startingString, endingString);

Nice but bear in mind the extension method can only access the public parts of the class it will appear with – there is no privileged access to protected properties or methods that would be available with subclassing!

[)amien

Colour schemes for Visual Studio

The default syntax colour/color scheme in Visual Studio seems to be stuck in the 16-colour era so once you’ve found your perfect font you are going to need a great theme to go with it.

Here is the theme I’m currently using at home (currently on a 42″ 1900×1200 LCD TV until I can find space for my monitor) that a couple of people have asked for.

To to take full advantage of this theme you will need to download:

  • Envy Code R for the syntax font with the italics hack
  • PalmOS for the output window’s tiny text

Alternatively you could remap it to your coding font of choice (but you won’t get italics because of limitations within the Visual Studio IDE).

Screen shot of Envy Code R PR7 with HumaneStudio theme.

Download Humane Studio theme (2KB, 14 Oct 2007)

Head to Humane Studio at Studio Styles for VS 2010

To use simply unpack the zip file and go to Tools > Import and Export Settings from Visual Studio (2005 and later).

Humane is now available for TextMate & Xcode 3.

If this scheme doesn’t appeal to you then why not try:

[)amien

Older pixel fonts back online

Some of my older bitmap “pixel” font files are now available again, they are:

  • Envy Code A – sizes from 7pt-12pt in both regular and bold weights
    Envy Code A font at 7pt regular
  • Envy Code B – sizes from 9pt-10pt in regular, bold, italic and bold italic. (was the basis for Envy Code R)
    Envy Code B font at 9pt regular
  • PalmOS – a Window port of the PalmOS system font recreated from screenshots.
    PalmOS font at 8pt regular

I also have about 20 pixel fonts from my Spectrum days that I am intending on bringing across to Windows FON format in the near future.

[)amien