2

バックグラウンド

この質問は、Delphi Prism のアスペクト指向プログラミング用の新しいCirrusインフラストラクチャに関連しています。

現在、クラスに自動注入している側面があり、Method.SetBody関数を使用してターゲット コードを変更しようとしています。これまでのところ、 Cirrus Introductionドキュメント wikiにある Logging のサンプル コードをベースとして使用して、コードを構成しました。

質問

元の関数本体が実行されている場合と実行されていない場合の両方で、注入される関数の Result にアクセスするにはどうすればよいですか?

1 つのコード パスで OriginalBody への呼び出しをバイパスする関数の結果を設定し、もう 1 つのコード パスとして OriginalBody を呼び出し、アスペクト コードで OriginalBody の後続の結果を使用できるようにしたいと考えています。私は当初、これがAspects.RequireResultメソッドの意図された目的である可能性があると考えていましたが、これは私の場合、OriginalBody の実行を強制するように見え、コードの重複を引き起こします。

4

1 に答える 1

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;
于 2009-06-05T04:49:23.553 に答える