String.IsNullOrEmpty as Extension Method

.NET Comments

Most you will probably know about Extension Method introduced with C# 3.0. If not, I strongly recommend to read ScottGu's explanation.

Anyway, a couple of days ago Brad Wilson posted an experiment:

What I wasn't sure was whether or not you could call these extension methods when you have a null instance of the object, since they're instance methods. The C++ guy in me said "sure, that should be legal", and the C# guy in me said "it's probably illegal, and that's too bad". Amazingly, the C++ guy in me won!

This code executes perfectly:

using System;

public static class MyExtensions {
    public static bool IsNull(this object @object) {
        return @object == null;
    }
}

public class MainClass {
    public static void Main() {
        object obj1 = new object();
        Console.WriteLine(obj1.IsNull());

        object obj2 = null;
        Console.WriteLine(obj2.IsNull());
    }
}

When you run it, it prints out "False" and "True". Excellent!

When I read that I immediatley thought of another application. I guess all my readers are familiar with String.IsNullOrEmpty which was introduced with .NET 2.0. So I asked myself if you can make IsNullOrEmpty a parameterless extension method:

using System;

public static class MyExtensions
{
    public static bool IsNullOrEmpty(this String s)
    {
        return String.IsNullOrEmpty(s);
    }
}

public class MainClass
{
    public static void Main()
    {
        string s1 = "Hello world";
        Console.WriteLine(s1.IsNullOrEmpty());

        string s2 = null;
        Console.WriteLine(s2.IsNullOrEmpty());
    }
}

Again, it prints out false and true. And in my opinion this syntactic sugar looks much more elegant than the ordinary String.IsNullOrEmpty(s2)`.

If only C# would support extension properties...

Goodbye Aachen, Hello Hamburg

Hamburg, Proximity, Cycos Comments

Cycos

After more than 8 years I´ll leave my current employer Cycos by the end of this year. Starting 1/1/08 I'll work as a Senior Software Developer at Proximity (international website.)

Cycos is my first employer, I started here right after university in 1999. Originally I didn't plan to stay that long here but 5 years at maximum. However, because the work was so diversified and the working atmosphere so prolific, I stayed some years longer. E.g. I was delegated to Munich and San Jose (CA) for several month each, and they paid me the attendances and expenses for both PDC´03 and ´05 in LA. In other words, I can´t accuse myself of being inflexible or inmobil. And it was always fun working at Cycos. I´ll be contended if the working atmosphere at my new job is half as prolific as I got to know it in the past.

However, after 8 years it´s time for a change. Most of my time at Cycos I wrote proprietary software, mainly clients for computer telephony integration. In contrast, at Proximity I will leverage Microsoft products such as MOSS and BizTalk, i.e. areas I don´t have a clue about where I can gain experience. But don´t get me wrong, I´m really looking forward for the new job.

Proximity

And I´m not only changing the employer, but the town as well. I´ll move to Hamburg, which is 500 km away from Würselen/Aachen (for my American friends: that´s about 310 miles). Therefore the search of a new domicile has my highest priority at the moment. I have 18 paid leave days left, and I want to complete my relocation this year. So this blog will stay quite silent the next few weeks. But stay tuned, I´ll keep you informed.

XTOPIA 2007

Community, Conference, Xtopia Comments

Now Germany has its own Mix conference, though here Microsoft calls it Xtopia. It will cover Silverlight, WPF, the Expression suite, and much more. It will take place in Berlin from 10th to 12th of October (if you include the post-conference on Friday).

I'll go to Berlin tomorrow already, and stay until Saturday. My Hotel is the Quality Hotel & Suites Berlin City East. If you want to join me for a beer or two, drop me a line or call me at +49 (173) 285 21 81. Lars, I'm expecting your call.

All Firefox Extensions Gone after upgrading to 2.0.7

Software, Tips 'n Tricks, Firefox Comments

Firefox

Today I upgraded Firefox to 2.0.7, which fixes a flaw in the QuickTime plugin. However, after the upgrade Firefox didn't load any of the extensions I have installed

Fortunately I found this thread in the support forum. Simply delete extensions.ini, extensions.cache, and extensions.rdf from your profile folder. On its next start Firefox will scan for installed extensions and regenerate these files.

I hope this post will be indexed properly so you can find this information faster than me.

Shot myself in the foot

If you have tried to leave a comment on my site in the last two days, you may have noticed that they weren´t accepted. Here is why:

Because the rate of incoming spam decreased dramatically after I implemented the Honeypot CAPTCHA on this site, I wondered if I could really give that solution the credit. Therefore I entered a comment myself to check it. And what happened? Nothing! Instead, that small red asterisk appeared next to the comment field, indicating that nothing was entered. WTF? I did enter some text! Garbage, I admit, but at least a few characters. Then I remembered that I switched the identifiers of the regular comment text box and the honeypot box. Then I had a sneaking suspicion, and I quickly checked post.aspx. My apprehension proved true: I have forgotten to point the RequiredFieldValidor to the other identifier! So as long as you didn't fill in the hidden honeypot, you couldn't post your comment. How stupid is that? The ironic side of the story is, that only comment spammers were able to cross that barrier, just to get marked as spam instantly afterwards.

Anyway, it´s fixed by now, and your comments are welcome (again)!