2009-06-04 96 views
2

背景德尔福棱镜Cirrus的访问和设置功能

这个问题涉及到新Cirrus基础设施在德尔福棱镜面向方面编程的结果。

我目前有一个方面,我自动注入一个类,并试图修改目标代码使用aMethod.SetBody函数。我已经使用Cirrus Introduction文档维基上的Logging示例代码作为基础,结构化了我的代码。

问题

我如何可以访问函数的结果被注入,既没有原来的函数体被执行?

我希望能够在一个代码路径中设置绕过对OriginalBody调用的函数的结果,并将其作为调用OriginalBody的其他代码路径,并在我的Aspect代码中使用OriginalBody的后续Result。 我原本以为这可能是Aspects.RequireResult方法的预期目的,但这似乎强制执行我的情况下的OriginalBody,导致代码重复。

回答

2

你的意思是这样的吗?

原始的方法: -

method Something.SomeMethod(a:Integer;b:Integer;c:Integer): Integer; 
begin 
    result:=b+c; 
end; 

的新方法: -

begin 
if (a > 0) then 
begin 
    result := (b + c); 
    exit 
    end; 
begin 
result := 1000; 
exit 
end 

该方法水平方面应该是这样的

[AttributeUsage(AttributeTargets.Method)] 
    Class1Attribute = public class(System.Attribute, 
    IMethodImplementationDecorator) 
    private 
    protected 
    public 
    method HandleImplementation(Services: RemObjects.Oxygene.Cirrus.IServices; aMethod: RemObjects.Oxygene.Cirrus.IMethodDefinition); 
    end; 

implementation 

method Class1Attribute.HandleImplementation(Services: RemObjects.Oxygene.Cirrus.IServices; aMethod: RemObjects.Oxygene.Cirrus.IMethodDefinition); 
begin 

    var newVersion:=new ResultValue(); 

    var newAssignment:=new AssignmentStatement(newVersion,new DataValue(1001)); 

    var p1:= new ParamValue(0); 

    aMethod.SetBody(Services,method 
    begin 
     if (unquote<Integer>(p1)>0) then 
     begin 
     Aspects.OriginalBody; 
     end 
     else 
     begin 
     unquote(newAssignment); 
     end; 
    end); 

end; 
+0

如果我尝试使用中的字符串Datavalue(目标函数返回一个字符串)我得到一个内部错误。如果我使用字符串,这个代码是否需要更新? – jamiei 2009-06-10 17:10:15