Skip to main content

Antonio Cisternino's Home Page

Go Search
Antonio Cisternino's Home Page > My Blog > Metaprogramming is Spreading Fast  

My Blog: Metaprogramming is Spreading Fast


Metaprogramming is Spreading Fast 


In a MSDN  article Karsten Januszewski ( discusses how the upcoming Indigo (more info in this article by Don Box, infrastructure relies on Custom Attributes for implementing asynchronous, bidirectional web services.
Microsoft introduced custom annotations with .NET, but the idea has shown to be so good that Java borrowed for Tiger (Java 1.5). Custom attributes provides a mean for annotating classes, methods and all the decorations of types.
The idea is to have a general way to tag program elements so that we can write programs that manage other programs.
Web services are a clever example of this approach:
class Foo {
  public string Echo(string s) {
    return string.Format("Echo '{0}'", s);
When you compile this class you get an executable that behave exactly like the one without the [WebMethod] annotation.
How is it possible to invoke the Echo method as a web service? The answer is easy: the ASP.NET runtime retrieves the attributes of classes and methods looking for methods labelled with [WebMethod]. When an annotated method is found the WSDL and SOAP interfaces are generated for it.
Now Indigo seems to rely more heavily on Custom Attributes to orchestrate distributed communications among software components. Consider the following interface definition:
public interface IHelloChannel : System.MessageBus.Services.IDatagramPortTypeChannel {
    string Greeting(string name);
Note how attributes are used extensively to provide information about how to expose the interface. It seems that there is some hope that in the future the plumbing needed for communication will be generated from our programs! I hope this will become reality.
As a matter of fact custom attributes are used as a mean to wave aspects into program without having to change it source at all: at runtime code for aspects is executed before and after methods.
I think that frameworks relying on annotations show an interesting trend of an increasing number of programs whose purpose is to manage other programs. Reflective execution environments such as CLR and JMV provide plenty of mechanisms to support this trend, and we are goin' towards a better engineering of our software (at least more consistent).
It's a pity that in the overall picture an important piece is still missing: a full model of annotations encompassing decorations as well as code inside methods. To fill this gap we have implemented [a]C#, a small extension to the C# programming language to annotate code blocks. The compiler is part of the CodeBricks initiative and is available in the project home page (




Created at 3/27/2004 14:16  by Antonio Cisternino 
Last modified at 3/27/2004 14:52  by Antonio Cisternino