(picture)

March 26, 2004

C# attributes

One of the powerful thing about .NET languages is the ability to define custom attributes on sourcecode (methods, classes, and so on), and so have very a very concise meta-programming syntax. Two great examples today:

Forms development in InfoPath SP1 (preview download) can now include .NET languages (your previous choices being JScript or VBScript). There's a little Visual Studio addin which hooks these together using custom attributes. An example via Aaron Skonnard:
[InfoPathEventHandler(MatchPath="Button1", EventType=InfoPathEventType.OnClick)]
public void Button1_OnClick(DocActionEvent e)
{
// Write your code here
...
}

And a wildly general use of attribute extensions: XC# "can influence the way the compiler works by adding or removing statements, renaming classes and members or canceling custom attribute generation... comes with compilation attributes for obfuscation, declarative assertions, code coverage, design rules, code verification, spell checking and more..."