API Overview

Cirrus is a small .NET library with interfaces and classes that can be used to build and adjust the code model in the compiler. There are two ways to use Cirrus, through an aspect attribute or a method override.

.NET Only

While aspects can be used on all three platfroms, but they can be only implemented using .NET.

Aspect attributes

Aspect attributes are plain .NET attributes that implement 1 or more of the cirrus interfaces. These attributes are placed in a regular .NET class library.

Interface Description
ITypeInterfaceDecorator Interface to be implemented by any aspect that wants to influence the signature of a type, modify the ancestry or add members
IEventInterfaceDecorator Interface to be implemented by any aspect that wants to influence the interface of an event.
IPropertyInterfaceDecorator Interface to be implemented by any aspect that wants to influence the interface of a property.
IMethodInterfaceDecorator Interface to be implemented by any aspneect that wants to influence the interface of a method.
IFieldInterfaceDecorator Interface to be implemented by any aspect that wants to influence any fields defined in a class
IEventImplementationDecorator Interface to be implemented by any aspect that wants to influence the implementation of an event.
ITypeImplementationDecorator Interface to be implemented by any aspect that wants to influence the implementation of a type.
IPropertyImplementationDecorator Interface to be implemented by any aspect that wants to influence the implementation of a property.
IMethodImplementationDecorator Interface to be implemented by any aspect that wants to influence the implementation of a method.

All the *InterfaceDecorator interface will be called early on, before any method bodies are resolved or generated. The *ImplementationDecorator interfaces are called after the body of that member was generated and processed. An aspect can implement multiple interfaces and if an aspect applied to a type implements one of the member interfaces will apply to all relevant membes of the call too.

The aspects all have a method with a services parameter that can be used to emit messages, find or create types and even add references to the project. The other parameter is a reference to the member this aspect is applied to.

Using aspect attributes

First in the project that will use the aspect add a "Cirrus Reference" to the aspect library. To use these aspects an aspect: (Oxygene) or __aspect: (RemObjects C#) prefix is used in the attribute. These aspects will not be compiled into the target executable.

Method aspects

Method aspects are aspects that get triggered when a call to a specific method is done, this aspect lets you replace the call with something else. Method aspects can be defined by applying MethodAspectAttribute to a class that implements IMethodCallDecorator. The constructor has several overloads that can be used to narrow down the method(s) to apply the aspect to, the method in this interface then gets called for each such method. Just referencing an aspect library with method aspects activates them. Method aspects get a context parameter that contains the services, the current type and method, a parameter with the method that was called and a parameter with the parameters to this call.