wliao008 / buffalo

an aspect oriented programming framework using mono cecil for the .NET platform
1 stars 0 forks source link

Rethink how the Around aspect is suppose to work #8

Closed wliao008 closed 11 years ago

wliao008 commented 11 years ago

Suppose I want to replace this method via aspect:

int add (int a, int b){
    return a+b;
}

when I use it

var r = add (1, 2);

it should call the generated method instead: -> add124940384545 (1,2); //generated method

int add124940384545(int a, int b){
    var aroundAspect = new MyAroundAspect();
    //if has return type
    return aroundAspect.Invoke(...);
    //if no return type
    aroundAspect.Invoke(...);
    return;
}

and the around aspect would like something like:

public class MyAroundAspect() : MethodAroundAspect{
    public override object Invoke(MethodArgs args){
        if(10 % 2 == 0){
            return args.Proceed(); //-> calls back to add(1,2);
        }else{
            return 99;
        }
    }
}

public class MethodArgs{
    //...
    public object Proceed(){return null;}
}
wliao008 commented 11 years ago

Current progress as of 10/29/2012.

The above has been implemented, however, when the generated method returns, garbage value was returned. MethodArgs.Invoke(..) functioned as expected, correct value is returned. Even inside the generated method, if I output the final value being returned, the value displayed is correct. However once that value got back to the call the value is lost. How come??