Compiler wish list: Attributes & Lambda Expressions

time to read 3 min | 443 words

Right now, you can't pass delegates to attributes, which is a shame, this would open up a whole new world of powerful patterns. In C# 3.0, there are Lambda expressions, which make the idea even more attractive. Consider the following:

[Validation(string value => string.IsNullOrEmpty(value) )]

public string Name

{

    get { return _name; }

    set { _name = value; }

}

I'm certain that you can see the possibilities from here. This is declarative programming at its best, in my opinion. The nice part about this is that lambda expression can be serialized, and later they can be turned into code as well. This should turn out to be very powerful in many contextes.

I opened a ladybug here, please vote for it.