AopDotNetAddIn 0.11 (Copyright © 2003 Mohamed Mesalem) ___________________ Aspects in C# VB.Net J# Programming Guide __________________ I Codeing the aspect ____________________ we represent the aspect as a class derived from Aspect which is defined in AspectLib.dll in this class you write member functions that contain the advice code and the aspectDescriptor.xml will specify when and where this code will run. member variables or methods may be used as introductions by specifying this in the aspectDescriptor.xml . the member functions that are used as advices will need to access the context information of the join point such information is exposed by the member variable currentJoinPoint which provide some information on the current join point such as the object. method where the join point is. you can also access objects at the join point by listing them as argumentents to the advice method for example if you declare a pointcut like this : execution(* Point.Set*(int,int)) you can declare your advice method like this void MyAdvice(Point pt,int x,int y) { .... } now the pt will represent the current point object that its set method is executed and x is the first argument it takes and y is the second one, note also that if Point derive from a class(or implemnt an interface) for example Foo you define the first argument to be of type Foo II Writing the weave instructions the aspectDescriptor.xml __________________________________________________________ this is the alternative of adding extensions to the Programming language to determine the set of joinpoints (poincut) at which the aspect code (advices) will run. the aspectDescriptor has a simple structure that you will use to quickly a user interface is currently being developed to ease you from wirting this file yourself untill then you will have to write it so we'll examine this file carefully a general structure of the file -the attributes of the node : name : the name of the aspect class code : the name of the file that contains the aspect class code weave: true or false determines whether to weave this aspect or not -the node : as we saw the advice code is represented as a method in the aspect class. the type attribute represents the advice type before,after or around. the node determines the aspect class method that contain the functionality of the advice. the node determines at what join points this advice will run, currently we can define only two types of join points: the execution join point (represented by the node) and the call join point (represented by the node) -the attributes of the , nodes : the values of these attributes may contain wild cards (ex:Set*) name : the name of the method class : the class name access : the access type of the method (public ,private...) return : the return type (int,void ...) -the : you can add new members,methods to a class or you can have a class implement a specific interface if you want to introduce a member or a method to a class this member or method should be already declared in the aspect if you want to have a class implement an interface then the aspect class must have implementations for all the interface methods III Using the AopDotNetAddIn ______________________ -In your Project choose add new item and choose aspect a class derived from Aspect will be added to your Project (if you did n't see an item named aspect then add a reference to AspectLib.dll which you can find at the location where you installed the Addin and then add your aspect class that is derived from Aspect) -an xml file named aspectdescriptor.xml will be added to the project -you can weave the aspect code by choosing Weave and run from the Build Menu