Generating code during postsharp compile

Share with us how you use PostSharp, or how you would like to use it.

Generating code during postsharp compile

Postby ThomasS on Fri Aug 08, 2008 8:58 pm

First of all I have to say I just started exploring PostSharp. I have looked into Sprint.Net and Castle Windsor before. But in general, I'm relative new to AOP.

What I would like to do with PostSharp is automatically creating asynchronous methods and event handlers for non-void methods.

Suppose you have an Interface IOrderService. And a few classes that implement that interface. I want to inject code into these classes so they have asynchronous method calls and event handlers to handle return values.

For example:
Code: Select all
public interface IOrderService
{
   void CreateOrder(order);
}

public class OrderWebService : WebService, IOrderService
{
    public void CreateOrder(order){
          //Calling the CreateOrderWebMethod
          base.Invoke(....);
   }
}

This class should then, after postsharp compilation, have the following extra methods:

public class OrderWebService : WebService, IOrderService
{
     public void CreateOrder(order){
          //Calling the CreateOrderWebMethod
          base.Invoke(....);
    }

     //generated method
     public void CreateOrderAsync(order){
          //Calling the CreateOrderWebMethod
         base.InvokeAsync(.....)
    }
   
     public event CreateOrderCompleted OnCreateOrderCompleted;
}



I don't know if this is possible with postsharp. It won't surprise me if it is. But i don't find any amples that create extra code. Can you give me any keywords, push in the right direction,..?

Many thanks in advance
Thomas
ThomasS
 
Posts: 1
Joined: Fri Aug 08, 2008 8:34 pm
First Name: Thomas
Last Name: Smets
Company: eXsertus

Re: Generating code during postsharp compile

Postby gfraiteur on Sat Aug 09, 2008 9:17 am

You could do it using PostSharp Core, but I wonder if it would not be better to use partial classes and a classic code generator.

-gael
Gael Fraiteur, project leader
gfraiteur
Site Admin
 
Posts: 834
Joined: Tue Dec 18, 2007 3:09 pm
First Name: Gael
Last Name: Fraiteur
Company: postsharp.org


Return to What To Do With PostSharp?